Android -- 无法播放任何视频(mp4/mov/3gp/等)?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2544365/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android -- Can't play any videos (mp4/mov/3gp/etc.)?
提问by RyanM
I'm having great difficulty getting my Android application to play videos from the SD card. It doesn't matter what size, bitrate, video format, or any other setting I can think of, neither the emulator nor my G1 will play anything I try to encode. I've also tried a number of videos from the web (various video formats, bitrates, with and without audio tracks, etc.), and none of those work either.
我很难让我的 Android 应用程序从 SD 卡播放视频。无论大小、比特率、视频格式或我能想到的任何其他设置,模拟器和我的 G1 都不会播放我尝试编码的任何内容。我还尝试了许多来自网络的视频(各种视频格式、比特率、带和不带音轨等),但这些都不起作用。
All I keep getting is a dialog box that says:
我一直得到的只是一个对话框,上面写着:
"Cannot play video"
“无法播放视频”
"Sorry, this video cannot be played."
“抱歉,这部影片无法播放。”
There are errors reported in LogCat, but I don't understand them and I've tried searching the Internet for further explanations without any luck. See below:
LogCat 中报告了错误,但我不明白它们,我尝试在 Internet 上搜索进一步的解释,但没有任何运气。见下文:
03-30 05:34:26.807: ERROR/QCOmxcore(51): OMXCORE API : Free Handle 390d4
03-30 05:34:26.817: ERROR/QCOmxcore(51): Unloading the dynamic library for OMX.qcom.video.decoder.avc
03-30 05:34:26.817: ERROR/PlayerDriver(51): Command PLAYER_PREPARE completed with an error or info PVMFErrNoResources
03-30 05:34:26.857: ERROR/MediaPlayer(14744): error (1, -15)03-30 05:34:26.867: ERROR/MediaPlayer(14744): Error (1,-15)
Sometimes I also get this:
有时我也会得到这个:
03-30 05:49:49.267: ERROR/PlayerDriver(51): Command PLAYER_INIT completed with an error or info PVMFErrResource
03-30 05:49:49.267: ERROR/MediaPlayer(19049): error (1, -17)
03-30 05:49:49.347: ERROR/MediaPlayer(19049): Error (1,-17)
Here is the code I'm using (in my onCreate() method):
这是我正在使用的代码(在我的 onCreate() 方法中):
this.setContentView(R.layout.main);
//just a simple VideoView loading files from the SD card
VideoView myIntroView = (VideoView) this.findViewById(R.id.VideoView01);
MediaController mc = new MediaController(this);
myIntroView.setMediaController(mc);
myIntroView.setVideoPath("/sdcard/test.mp4");
myIntroView.requestFocus();
myIntroView.start();
Please help!
请帮忙!
回答by RyanM
Okay, here goes. The video I've been working on in Adobe Premiere is supposed to be 480x800 (WxH), but I have the Adobe Media Encoder output the sequence as an "Uncompressed Microsoft AVI" using the "UYVY" video codec, 24fps frame rate, progressive, square pixels, and dimensions: 720x800 (WxH). This outputs a rather large file with 120px black borders on either side of the video content. I then take the video into Handbrake 0.9.4 and use the following settings (I started with the Regular->Normal preset):
好的,这就去。我在 Adobe Premiere 中处理的视频应该是 480x800 (WxH),但我让 Adobe Media Encoder 使用“UYVY”视频编解码器将序列输出为“未压缩的 Microsoft AVI”,24fps 帧速率,逐行、方形像素和尺寸:720x800 (WxH)。这会输出一个相当大的文件,在视频内容的两侧都有 120 像素的黑色边框。然后我将视频放入 Handbrake 0.9.4 并使用以下设置(我从常规->正常预设开始):
Container: MP4 File
Large file size: [un-Checked]
Web-optimized: [un-Checked]
iPod 5G support: [un-Checked]
Width: 320 (this is key, any higher than 320 and it won't work)
Height: 528
Keep Aspect Ratio: [Checked]
Anamorphic: None
Crop Left: 120
Crop Right: 120
Everything under the "Video Filter" tab set to "Off"
Video Codec: H.264(x264)
Framerate: same as source
2-Pass Encoding: [Checked]
Turbo first pass: [un-Checked]
Avg Bitrate: 384
Create chapter markers: [un-Checked]
Reference Frames: 2
Mixed References: [un-Checked]
B-Frames: 0
Motion Estimation Method: Uneven Multi-Hexagon
Sub-pixel Motion Estimation: 9
Motion Estimation Range: 16
Analysis: Default
8x8 DCT: [un-Checked]
CABAC Entropy Coding: [un-Checked]
No Fast-P-Skip: [un-Checked]
No DCT-Decimate: [un-Checked]
Deblocking: Default, Default
Psychovisual Rate Distortion: [MAX]
My main problem was that I was trying to output an mp4 file with 480x800 (WxH) dimensions. After changing the width to 320 (higher values didn't work), yet keeping the proper aspect ratio, the output video now plays without errors. I hope this helps someone else with a similar problem.
我的主要问题是我试图输出一个 480x800 (WxH) 尺寸的 mp4 文件。将宽度更改为 320(更高的值不起作用),但保持适当的纵横比后,输出视频现在可以正常播放。我希望这可以帮助其他有类似问题的人。
Side note: I wish the Android video restrictions were better documented.
旁注:我希望能更好地记录 Android 视频限制。
回答by Donald Scott Wilde
I have had quite a bit of trouble getting many different videos to play on my phone (HTC hero). Standard 512K mp4's play (example: http://www.archive.org/details/more_animation), check with them first to make sure it's not your code.
我在手机(HTC 英雄)上播放许多不同的视频时遇到了很多麻烦。标准 512K mp4 播放(例如:http: //www.archive.org/details/more_animation),首先与他们核对以确保它不是您的代码。
Here's my code, from onCreate() in a sub-activity which only plays the video file:
这是我的代码,来自仅播放视频文件的子活动中的 onCreate():
protected VideoView mine;
protected boolean done = false;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.videoshow);
mine = (VideoView) findViewById(R.id.video); // Save the VideoView for touch event processing
try {
String myURI = "/sdcard/" + path + "/v/"
+ currentItem.getFile()
+ "." + currentItem.getFileType();
Uri video = Uri.parse(myURI);
mine.setVideoURI(video);
mine.start();
mine.setOnCompletionListener(new OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
result.putExtra("com.ejf.convincer01.Finished", true);
done = true;
}
});
} catch (Exception ex) {
Log.d(DEBUG_TAG, "Video failed: '" + ex + "'" );
}
回答by Mansour Fahad
I was facing this problem until I figured out that the problem was in the directory of my video. I was saving my videos to a directory that is unreachable to the video view. So every time I try to play a video it gives me error message says: "Can't open video" or something like that. Try and save your video to this directory which will be also visible in phone gallery.
我一直面临这个问题,直到我发现问题出在我的视频目录中。我将视频保存到视频视图无法访问的目录中。因此,每次我尝试播放视频时,它都会给我错误消息:“无法打开视频”或类似内容。尝试将您的视频保存到此目录,该目录也可在手机图库中看到。
String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + "/" + "your app name ";