2014-09-27 144 views
2

我通过HTTP在自定义VideoView上成功传输视频。通过HTTPS流式传输MP4视频时MediaPlayer出错

但现在,我试图通过HTTPS流式传输已签名的视频。

让我们下面的网址,例如:

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

那些请求的认证头,从我所要建造的地图标题:

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

,我已经使用setDataSource (Context context, Uri uri, Map<String, String> headers)用于较新版本的Android,Java reflectionICE_CREAM_SANDWICH之前的标头调用隐藏的setDataSource方法。与地图上的所有以前的标题。

自定义 VideoView.java

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; 
    } 
} 

和播放时,我得到这个错误:

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

编辑:我想说明,这不是由于视频格式,因为当我下载这个视频并将其存储到手机的外部存储器时,可以使用我的自定义功能播放VideoView

有什么办法可以解决这个问题吗?

谢谢。

+0

http://stackoverflow.com/questions/22073970/how-to-embed-vlc-media-player-to-my-android-app – koutuk 2014-10-04 09:49:05

+0

都去了哪里通过这个,http://developer.android.com/guide/appendix/media-formats.html可能是你的编码不​​支持。 – Chitrang 2014-10-04 20:12:36

回答

2

可能是你麻烦的SSL证书。尝试读取这个参考之前,您的主要代码信任所有证书:Trusting all certificates using HttpClient over HTTPS,Accepting a certificate for HTTPs on Android,http://blog.denevell.org/android-trust-all-ssl-certificates.html

可能是这个希望你。

我用这个代码:

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) {} 
+0

谢谢。但是我可以通过HTTPS检索任何数据/流/文档,流操作的行为是否有所不同?我需要明确地让android信任它们吗? – Copernic 2014-10-07 12:57:58