Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android VideoView Cannot play video mp4

I used the Android VideoView to play a video file via HTTP. My problem is my phone prompts "Cannot play video Sorry, this video cannot be played." when playing a mp4 file from HTTP. But it is ok when playing another mp4 video file.

When used in a newer phone, like Samsung Galaxy S, my program can play both mp4 video file from HTTP successfully.

My phone:

Samsung GT-S5830  
Android version: 2.3.4  
Display: 320x480.

Video file 1 (OK):  
Video Codec: H.264  
Resolution: 640x360  
Others: 16:9, 340kbps, 29.92fps  
Audio Codec: AAC, 44kHz 96kbps Stereo.


Video file 2 (Fail):  
Video Codec: H.264  
Resolution: 640x360  
Others: 16:9, 993kbps, 25fps  
Audio Codec: AAC 44kHz 125kbps Stereo.

Below is my code that hardcoded to play the video file 1 successfully.

public class VideoPlayActivity extends Activity {
VideoView vv;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //requestWindowFeature(Window.FEATURE_NO_TITLE);
    //getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

    vv = new VideoView(this);
    RelativeLayout.LayoutParams param1 = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
    param1.addRule(RelativeLayout.CENTER_IN_PARENT);
    vv.setOnErrorListener(new OnErrorListener() {

        public boolean onError(MediaPlayer mp, int what, int extra) {
            Log.d("Dbg", "OnErrorListener: onError: " + what + ", " + extra);
            return false;
        }

    });

    RelativeLayout layout = new RelativeLayout(this);
    layout.addView(vv, param1);

    setContentView(layout);

    playContent();

 }

 private void playContent() {
    String path = "http://rmcdn.2mdn.net/MotifFiles/html/1248596/android_1330378998288.mp4";

    vv.setVideoPath(path);
    vv.requestFocus();
    vv.start();
    }
}

The error log when playing video file 2 is as below:

11-19 17:49:30.119: I/VideoView(16860): start()  
11-19 17:49:30.139: E/MediaPlayer(16860): error (1, -2147483648)  
11-19 17:49:30.149: E/MediaPlayer(16860): Error (1,-2147483648)  
11-19 17:49:30.149: D/VideoView(16860): Error: 1,-2147483648  
11-19 17:49:30.149: D/Dbg(16860): OnErrorListener: onError: 1, -2147483648  

It is noted that I tried to install the MX player and downloaded the both video file into my phone's SD card. The MX player can play both video files successfully.

So, can anyone help me to answer the questions below:

  1. Why my program cannot play the video file 2 on my phone?
  2. How can I play the video file 2 on my phone?

Thank you for your advice.

like image 231
tim Avatar asked Nov 19 '12 09:11

tim


People also ask

Can t play video from SD card Android?

If you are unable to play videos saved on the SD card of your device, ensure, your SD card is not loose and is correctly inserted in your phone. So, check the SD card and make sure it is locked in its place.


1 Answers

Thanks for the answer from Android MediaPlayer error (1, -2147483648).

I found the video file 2 was encoded in H.264 Main Profile, that my mobile phone cannot be played. Android Supported Media Format suggests H.264 in Baseline Profile. So after converting the video to Baseline Profile, it can be played on my phone.

like image 177
tim Avatar answered Oct 13 '22 01:10

tim