gpt4 book ai didi

android - 通过 HTTPS 流式传输 MP4 视频时出现 MediaPlayer 错误

转载 作者:行者123 更新时间:2023-11-29 00:16:46 25 4
gpt4 key购买 nike

我在自定义 VideoView 上成功地通过 HTTP 流式传输视频。

但现在,我正在尝试通过 HTTPS 流式传输签名视频。

让我们以下面的 URL 为例:

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

这些是请求的身份验证 header ,我从中构建 map header :

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 reflection使用 ICE_CREAM_SANDWICH 之前的 header 调用隐藏的 setDataSource 方法.在 map 上包含所有以前的标题。

在自定义中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

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

谢谢。

最佳答案

可能是你的 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) {}

关于android - 通过 HTTPS 流式传输 MP4 视频时出现 MediaPlayer 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26074747/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com