我一直在尝试使用MediaPlayer类在Android 2.1上播放H.264编码的视频,但一直没有进展。我的代码非常简单:
AssetFileDescriptor fileDescriptor = getResources().openRawResourceFd(R.raw.my_movie);
introMoviePlayer = new MediaPlayer();
introMoviePlayer.setDataSource(fileDescriptor.getFileDescriptor(), fileDescriptor.getStartOffset(), fileDescriptor.getDeclaredLength());
introMoviePlayer.prepare();
这总是在prepare()
处抛出异常,异常信息为java.io.IOException:Prepare failed .: status=0x1
。通过使用带有URI的MediaPlayer.create()
,我获得了更多信息,它也在prepare()
处抛出异常,实际上由MediaPlayer.create()
调用,并显示消息Command PLAYER_PREPARE completed with an error or info PVMFErrResourceConfiguration
。
相同的代码在Froyo(2.2)中完美运行。这些视频在视频播放器应用程序中也可以正常播放。是否有人可能有一个有用的提示,可以帮助解决这个问题?
编辑:仍然没有解决方案-非常令人沮丧的问题。但是,我发现通过创建一个VideoView
并为原始视频设置URI可行。这非常令人困惑,因为将完全相同的URI通过MediaPlayer类发送将导致异常。