Android VideoView Cannot play video mp4

白昼怎懂夜的黑 提交于 2019-11-30 03:13:20

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/13451180/android-videoview-cannot-play-video-mp4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!