2014-09-27 191 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