从HTTPS网址流式传输视频时出错 [英] Error in streaming a video from HTTPS url

查看:324
本文介绍了从HTTPS网址流式传输视频时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在正常的http中流式传输视频没有问题。
(例如: http://www.mywebsite.com/myvideo.mp4

I have no problem in streaming a video in a normal http. (example : http://www.mywebsite.com/myvideo.mp4)

但是当我将其更改为HTTPS时。我遇到错误
(例如: https://www.mywebsite.com/myvideo.mp4

But when i change it into HTTPS. I have encounter an error (example : https://www.mywebsite.com/myvideo.mp4)

有没有人试过这个?使用HTTPS链接将视频流式传输到第三方APP。 (通过将url / uri传递给android中的应用程序,询问用户将使用哪个应用程序播放视频)

Does anyone have tried this? Streaming a video with HTTPS link to a 3rd party APP. (asking a user which app will be use to play video, by passing the url/uri to the app in android)

目前的情况是:

1。)我有一个链接,这是https

1.) I have a link which is https

2.)我已经启动了一个意图,并检查所有可用的视频播放器安装在Android手机中(我目前已经安装了vlc,mx
播放器,videoplayer,内置OS播放器等)。

2.) I have start an intent , and check all available video player installed in android phone ( i have currently installed vlc , mx player , videoplayer, built in OS player and others).

3。)我尝试选择以上任何一种,但都不起作用。 (它只是提示一条消息,说玩家遇到错误,这是一个
的一般错误。我只是想把URL / URI传递给玩家)。

3.) I try to choose any of those above but none of them works. ( it just prompt a message, saying "Player encounter an Error" which is a generic error. Im just trying to pass the URL / URI to the player).

4。)请注意,如果我尝试在网络浏览器中播放它,一切正常。

4.) Please take note, if i try to play it in the web browser everything works fine.

5。)请再次注意,我是能够使用相同的代码流式传输http视频

5.) Please take note that again , I was able to stream http video, using same piece of code

String videoURL = "https://www.mywebsite.com/myvideo.mp4";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(videoURL));
intent.setDataAndType(Uri.parse(videoURL), "video/*");
startActivity(intent);

在我的清单文件中,我使用默认值,但我允许上网。

In my manifest file, im using the default, except that i give permission to the internet.

我不确定这是否相关或者这可以帮助但是:我能够缓冲来自同一个SERVER的HTTPS音频文件。因为android有一个内置的媒体播放器支持wav& mp3,我不是要求用户选择媒体播放器,因为它可以支持上述格式。当我在同一服务器中缓冲音频时,我只发出以下代码。所以一切都很好。

Im not sure if this is related or this can help but : I was able to buffer a HTTPS Audio FILE coming from same SERVER. Since android has a built in media player that supports wav & mp3, im not asking the user to choose a media player, since it can support the above format. When i buffer the audio in the same server, i just issue below code. So everyting works well.

public HttpClient getNewHttpClient() {
    try {
        KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
        trustStore.load(null, null);

        SSLSocketFactory sf = new MySSLSocketFactory(trustStore);
        sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

        HttpParams params = new BasicHttpParams();
        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
        HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);

        SchemeRegistry registry = new SchemeRegistry();
        registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
        registry.register(new Scheme("https", sf, 443));

        ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);

        return new DefaultHttpClient(ccm, params);
    } catch (Exception e) {
        return new DefaultHttpClient();
    }
}

`

但是当谈到播放视频时,即时通讯询问用户他想播放哪个APP,可能导致该文件不受支持。

But when it comes to playing video, im asking the user which APP he wants to play, cause the file might not be supported.

FIX

看起来,android在断链证书中有一些问题,为了解决这个问题,你必须修复破损的链证书。要查看您的证书,只需访问ssllabs.com/ssltest/analyze.html?d=yourwebsite.com

推荐答案

经过长时间的努力,我找到了解决方案,


覆盖您的视频观看课程及以下代码。

Override your videoview class and below code.



 @Override
public void setVideoURI(Uri uri) {
    super.setVideoURI(uri);
    try {
        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);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

这篇关于从HTTPS网址流式传输视频时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆