从 https 链接传输音频时出现问题

发布于 2024-10-21 01:37:56 字数 211 浏览 2 评论 0原文

大家好,我对 Android 有点陌生,我开发了一个应用程序,它从服务器流式传输音频,一切都很顺利,直到我的应用程序崩溃,我对其进行了调试,发现 Android 媒体播放器在通过 HTTPS 链接流式传输时抛出异常。我有大约 20 个将音频流式传输到我的应用程序的链接,其中大约一半是 HTTPS 链接,但它们没有播放。如果有人理解它,请回答我需要帮助,如果你能给我任何一段对我来说更容易理解的代码。提前致谢

Hi everyone I'm a bit new to android I have developed an app which is streaming the audio from server everything was going fine until my app crashed, I debugged it and found out the android media player is throwing exception while streaming through HTTPS link. I have almost about 20 links from where I'm streaming audio to my app and about half are HTTPS links and they are not playing. If anyone understand it please answer I need help, if you can give me any piece of code that would be much easier for me to understand.Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甜扑 2024-10-28 01:37:56

Android 媒体播放器不支持 HTTPS。如果您提供 HTTPS URL,则会下载该文件。

Android 文档中提供了“HTTPS”不受支持的事实。

Android media player doesn't support HTTPS. If you provide a HTTPS URL, then the file will be downloaded.

This "HTTPS" not supported fact is provided in android documentation.

自我难过 2024-10-28 01:37:56

只需在调用 mediaplayer MySSLSocketFactory 之前添加以下代码

KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
        trustStore.load(null, null);
        MySSLSocketFactory sf = new MySSLSocketFactory(trustStore);
        sf.setHostnameVerifier(MySSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
        sf.fixHttpsURLConnection();
        HostnameVerifier hostnameVerifier = org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;
        HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier);

https://github.com/joniks/Android-Async-HTTP/blob/master/library/src/main/java/com/loopj/android/http/MySSLSocketFactory.java

Just add below code before calling mediaplayer

KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
        trustStore.load(null, null);
        MySSLSocketFactory sf = new MySSLSocketFactory(trustStore);
        sf.setHostnameVerifier(MySSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
        sf.fixHttpsURLConnection();
        HostnameVerifier hostnameVerifier = org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;
        HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier);

MySSLSocketFactory: https://github.com/joniks/Android-Async-HTTP/blob/master/library/src/main/java/com/loopj/android/http/MySSLSocketFactory.java

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文