简体   繁体   English

Android VideoView无法播放视频mp4

[英]Android VideoView Cannot play video mp4

I used the Android VideoView to play a video file via HTTP. 我使用Android VideoView通过HTTP播放视频文件。 My problem is my phone prompts "Cannot play video Sorry, this video cannot be played." 我的问题是我的手机提示“无法播放视频抱歉,此视频无法播放。” when playing a mp4 file from HTTP. 从HTTP播放mp4文件时。 But it is ok when playing another mp4 video file. 但是播放另一个mp4视频文件时可以。

When used in a newer phone, like Samsung Galaxy S, my program can play both mp4 video file from HTTP successfully. 在三星Galaxy S等新手机中使用时,我的程序可以成功播放来自HTTP的mp4视频文件。

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. 下面是我的代码,硬编码成功播放视频文件1。

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: 播放视频文件2时的错误日志如下:

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. 请注意,我尝试安装MX播放器并将两个视频文件下载到手机的SD卡中。 The MX player can play both video files successfully. MX播放器可以成功播放两个视频文件。

So, can anyone help me to answer the questions below: 那么,任何人都可以帮助我回答以下问题:

  1. Why my program cannot play the video file 2 on my phone? 为什么我的程序无法在手机上播放视频文件2?
  2. How can I play the video file 2 on my phone? 如何在手机上播放视频文件2?

Thank you for your advice. 感谢您的意见。

Thanks for the answer from Android MediaPlayer error (1, -2147483648) . 感谢Android MediaPlayer错误(1,-2147483648)的答案。

I found the video file 2 was encoded in H.264 Main Profile, that my mobile phone cannot be played. 我发现视频文件2是用H.264 Main Profile编码的,我的手机无法播放。 Android Supported Media Format suggests H.264 in Baseline Profile. Android支持的媒体格式建议在Baseline Profile中使用H.264。 So after converting the video to Baseline Profile, it can be played on my phone. 因此,在将视频转换为Baseline Profile后,它可以在我的手机上播放。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM