Reputation: 81
I have no problem in streaming a video in a normal http. (example : http://www.mywebsite.com/myvideo.mp4)
But when i change it into HTTPS. I have encounter an error (example : https://www.mywebsite.com/myvideo.mp4)
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)
The current scenario is:
1.) I have a link which is https
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.) 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.) Please take note, if i try to play it in the web browser everything works fine.
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.
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();
}
}
`
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
It looks like , android has some problem in broken chain certificates, in order to fix this, you must fix your broken chain certificate. To check your certificate, simply go to ssllabs.com/ssltest/analyze.html?d=yourwebsite.com
Upvotes: 0
Views: 3981
Reputation: 6509
After long struggle i found solution,
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();
}
}
Upvotes: 2