0

I'm using Media Player in my Android application. The videos from http link is playing in all versions of android, but the https link is playing only in Android 4.1.2, but in lower versions it is not playing. Showing following error..

java.io.IOException: Prepare failed.: status=0x1 Error(1,-18).

I'm using the following code

   MediaPlayerplayer = new MediaPlayer();
    player.setOnPreparedListener(this);
player.setOnCompletionListener(this);
player.setOnBufferingUpdateListener(this);
player.setOnSeekCompleteListener(this);
player.setScreenOnWhilePlaying(true);
player.setDisplay(holder);

    try {
String videoUrl = getIntent().getExtras().get("url").toString();
    File mediaFile = new File(fileName);
if (mediaFile.exists()) {
    FileInputStream fi = new FileInputStream(mediaFile);
    player.setDataSource(fi.getFD());                   
    }
else{
    player.setDataSource(videoUrl);
}
RobinHood
  • 10,897
  • 4
  • 48
  • 97
Krishna
  • 4,892
  • 18
  • 63
  • 98

3 Answers3

2

try this one

  try {
        setContentView(R.layout.videodisplay);
        String link="Yourvideo link";
        VideoView videoView = (VideoView) findViewById(R.id.VideoView);
        MediaController mediaController = new MediaController(this);
        mediaController.setAnchorView(videoView);
        Uri video = Uri.parse(link);
        videoView.setMediaController(mediaController);
        videoView.setVideoURI(video);
        videoView.start();
    } catch (Exception e) {
        // TODO: handle exception
        Toast.makeText(this, "Error connecting", Toast.LENGTH_SHORT).show();
    }

and give internet permission in android manifest.xml and if you want to play using mediaplayer than click here

Community
  • 1
  • 1
Yogesh Tatwal
  • 2,722
  • 20
  • 43
1

Android versions above 3.1 only supports HTTPS media files. See the official link.

Krishna
  • 4,892
  • 18
  • 63
  • 98
1

After long struggle i found solution,that's why i share with you because it take too much time to find out answer

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();
    }
}
Yogesh Rathi
  • 6,331
  • 4
  • 51
  • 81