user1079425
user1079425

Reputation:

MediaPlayer error when streaming MP4 videos over HTTPS

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

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

let's take the following URL for example :

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, from which I build the Map headers :

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.

in the custom VideoView.java class :

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

EDIT : I would like to specify that this is not due to video format, since when I download this very video and store it to the external storage of the phone it can be played with my custom VideoView

Is there any way I can solve this ?

Thank you.

Upvotes: 2

Views: 2542

Answers (1)

Tapa Save
Tapa Save

Reputation: 4857

May be you trouble with ssl certificates. Try read this refs for trust all certificates before you main code: Trusting all certificates using HttpClient over HTTPS, Accepting a certificate for HTTPs on Android, http://blog.denevell.org/android-trust-all-ssl-certificates.html

May be this hope you.

I use this code:

  TrustManager[] trustAllCerts = new TrustManager[]
   { new X509TrustManager()
      {
        public java.security.cert.X509Certificate[] getAcceptedIssuers()  { return null; }
        public void checkClientTrusted( X509Certificate[] chain, String authType) {}
        public void checkServerTrusted( X509Certificate[] chain, String authType) {}
      }
   };

  try
    {
      SSLContext sc = SSLContext.getInstance( "SSL"); // "TLS" "SSL"
      sc.init( null, trustAllCerts, null);
      // sc.init( null, trustAllCerts, new java.security.SecureRandom());
      HttpsURLConnection.setDefaultSSLSocketFactory( sc.getSocketFactory());
      HttpsURLConnection.setDefaultHostnameVerifier( 
       new HostnameVerifier() 
        {
          public boolean verify( String hostname, SSLSession session) { return true; }
        } );
    }
   catch (Exception e) {}

Upvotes: 2

Related Questions