Android : MediaPlayer error when streaming videos over HTTPS

on Saturday, September 27, 2014


I'm successfully streaming videos over HTTP on a custom VideoView.


But now, I'm trying to Stream a signed video over HTTPS.


https://api.akm.info/users/5e2badf4-4e63-4e36-929e-90f7be3e407a/videos/UxZkUACjSyxZhjzG?lat=45.6574&lng=150.234


those are the authentication headers of the request :



Akm-Client-Timestamp : 2014-09-27T12:18:07Z
Authorization : AKM wdMTVz5Oesgf+UVWO4CX:546gtSMWUPhP8kKPJFaBgZTzWALj/kx3PASz+Y/Za08=
ACCEPT : application/json


and I've used setDataSource (Context context, Uri uri, Map<String, String> headers ) for newer versions of Android and Java reflection to call the hidden setDataSource method with headers prior to ICE_CREAM_SANDWICH. with all the previous headers on a Map.



if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
mMediaPlayer.setDataSource (getContext(), mUri, mHeaders);
} else {
Method method = null;
try {
method = mMediaPlayer.getClass().getMethod("setDataSource", new Class[] { Context.class, Uri.class, Map.class });
} catch (NoSuchMethodException e) {
Log.w(TAG, "Unable to open content: " + mUri, e);
mCurrentState = STATE_ERROR;
mTargetState = STATE_ERROR;
mErrorListener.onError(mMediaPlayer, MediaPlayer.MEDIA_ERROR_UNKNOWN, 0);
return;
}

try {
method.invoke(mMediaPlayer, new Object[] {this, mUri, mHeaders});
} catch (IllegalAccessException e) {
Log.w(TAG, "Unable to open content: " + mUri, e);
mCurrentState = STATE_ERROR;
mTargetState = STATE_ERROR;
mErrorListener.onError(mMediaPlayer, MediaPlayer.MEDIA_ERROR_UNKNOWN, 0);
return;
} catch (InvocationTargetException e) {
Log.w(TAG, "Unable to open content: " + mUri, e);
mCurrentState = STATE_ERROR;
mTargetState = STATE_ERROR;
mErrorListener.onError(mMediaPlayer, MediaPlayer.MEDIA_ERROR_UNKNOWN, 0);
return;
}
}


and when playing it I get this error :



MediaPlayer : error (1, -1004)
AwesomePlayer: mConnectingDataSource->connect() returned -1004


Can anyone help me with this ? is there any way I can solve this ?


Thank you.


0 comments:

Post a Comment