2

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

Talha
  • 809
  • 4
  • 13

2 Answers2

2

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.

  • 2
    Where in the docs is the info on https not supported? Didn't find it on http://developer.android.com/reference/android/media/MediaPlayer.html, though the setDataSource method description just says "Sets the data source (file-path or http/rtsp URL) to use." – Mathias Conradt Oct 12 '11 at 14:11
  • I'm just chiming in a year later to point out that the documentation claims that MediaPlayer does support HTTPS: http://developer.android.com/guide/appendix/media-formats.html. However this appears to still not be the case. – Thomson Comer Apr 17 '13 at 20:37
1

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

Angus Lam
  • 3
  • 1
Yogesh Rathi
  • 6,331
  • 4
  • 51
  • 81