Android--无法播放任何视频(mp4/mov/3gp等)?

6
我遇到了很大的困难,无法让我的Android应用程序从SD卡播放视频。无论大小、比特率、视频格式或任何其他设置,我都无法编码成功,模拟器和G1都无法播放。我还尝试了许多来自网络的视频(各种视频格式、比特率、有无音轨等),但这些也都不起作用。
我一直收到一个对话框,上面写着:
“无法播放视频”
“抱歉,无法播放此视频。”
LogCat中报告了错误,但我不理解它们,我已经尝试在互联网上搜索进一步的解释,但没有找到任何帮助。请参见下文:
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)

有时我也会遇到这种情况:
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)

这是我在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!

3个回答

10

好的,开始翻译。我在Adobe Premiere上制作的视频应该是480x800(宽x高),但我使用“UYVY”视频编解码器,24fps帧速率,渐进扫描,方形像素,并以720x800(宽x高)输出一个“未压缩的Microsoft AVI”序列。这将输出一个相当大的文件,其中视频内容的两侧有120像素的黑色边框。然后我将视频导入到Handbrake 0.9.4中,并使用以下设置(我从Regular->Normal预设开始):

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]

我的主要问题是我尝试输出一个480x800(WxH)像素尺寸的mp4文件。将宽度更改为320(更高的值无法工作),但保持正确的纵横比,输出视频现在可以无错误播放了。我希望这能帮助其他遇到类似问题的人。

顺便说一句:我希望Android的视频限制能够有更好的文档记录。


3
我非常赞同你的想法,我甚至按照你的示例操作,但仍无法流畅播放视频。另外,我希望安卓视频限制能有更好的说明文档。 - John Giotta
你能否把你写的代码发到这里?因为我实在看不懂,我是新手,需要帮助。非常感谢! - UMAR-MOBITSOLUTIONS
是的,使用VideoView和MediaPlayer确实很麻烦。感谢您的问答。 - Ovidiu Latcu
你能具体说明你在代码中做了哪些更改以解决问题吗?我也遇到了同样的问题,如果你能帮忙就请帮忙吧。 - MKJParekh
@Frankenstein 我并没有真正改变代码;我改变了应用程序(Handbrake...它是免费的)中的视频编码设置,以生成/编码视频。不过,这些设置可能对你不起作用。它们对我有用。 - RyanM

3

我在我的手机(HTC Hero)上播放许多不同的视频时遇到了很多麻烦。标准的512K mp4文件可以播放(例如:http://www.archive.org/details/more_animation),请先检查它们,确保不是你的代码问题。

这是我的代码,来自一个仅播放视频文件的子活动中的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 + "'" );
        }

谢谢您的回复。我采纳了您的建议,并从您提供的网站下载了一个视频,“The Lost Kitten 1938”(512k mpeg4),使用我提供的完全相同的代码,它完美地运行了。非常感谢您。我将尝试重新编码我的视频以匹配下载示例的规格,并返回发布详细信息。您是否知道我应该在编码器中使用哪些确切设置(我可以使用Adobe Media Encoder或Handbrake)? - RyanM

0
我曾经遇到过这个问题,直到我发现问题出在我的视频目录上。我把视频保存到了一个无法被视频查看器访问的目录中。所以每次我尝试播放视频时,都会出现错误消息,提示“无法打开视频”之类的信息。 尝试将您的视频保存到此目录中,该目录也将在手机相册中可见。
String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + "/" + "your app name ";

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接