Search code examples
androidmp4android-videoview

Failed to play mp4 video directly from URL in Android platform, is there any solution?


I am trying to play a video from URL on videoView. Video extension is mp4, and the problem is that an error appears like this :

enter image description here

and the logcat was like this:

![enter image description here][2]

Actually I found many questions here on stackoverflow.com but nothing were convenient. The problem is with mp4 format, I tried 3gp and it worked fine. I don't want to download the video then play it and I don't want to convert it to 3gp.

Appreciate your help.

EDIT:: Here is the code snippet

     String LINK =  "https://********/cbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcb.mp4";
    VideoView videoView = (VideoView) findViewById(R.id.videoView1);
    MediaController mc = new MediaController(this);  
    mc.setAnchorView(videoView);
    mc.setMediaPlayer(videoView);
    Uri video = Uri.parse(LINK);
    videoView.setMediaController(mc);
    videoView.setVideoURI(video);
    videoView.start();

Edit:

I don't know how to apply this recommendation from android site:

  For 3GPP and MPEG-4 containers, the moov atom must precede any mdat atoms, but must succeed the ftyp atom.
  For 3GPP, MPEG-4, and WebM containers, audio and video samples corresponding to the same time offset may be no more than 500 KB apart. To minimize this audio/video drift, consider interleaving audio and video in smaller chunk sizes.

Solution

  • Like @Giuseppe said HTTPS could be the problem, if you are using an Android version before 3.1. If see it over here: http://developer.android.com/guide/appendix/media-formats.html it says:

    Note: HTTPS is not supported before Android 3.1.

    Edit: Ensure that you in your manifest file you have the permission:

    <uses-permission android:name="android.permission.INTERNET" /> 
    

    Also test the video playing on a real device because sometimes the emulator has some problems.