3

我准备了一个代码来播放我的 res 文件夹中的一个简单的 mp4 文件。编码是这样的:

    public class VideoPlayer extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.video);
        VideoView video = (VideoView)findViewById(R.id.VideoView);
        Uri uri = Uri.parse("android.resource://company.software.myapp/"
                + R.raw.myvideo);
        MediaController mc = new MediaController(this);
        video.setMediaController(mc);
        video.setVideoURI(uri);
        //video.requestFocus();
        video.start();
    }
}

现在虽然播放没有错误。该活动会自动生成一个对话框,上面写着“抱歉无法播放此视频”,但我可以听到音频并且它一直播放到结束。问题是什么?

4

3 回答 3

4

非常感谢commonsware.com ......但我找到了问题的解决方案......令人惊讶的是它的PC处理器是罪魁祸首......我检查了更高的配置并猜测......它工作得非常好...... . 虽然有时如果我们在后台进行一些处理,对话框确实会出现,但点击确定它会在一段时间后开始播放视频......

但我确认,据我所知,这种从资源播放文件的技术是可以的......

很抱歉把你宝贵的时间浪费在一个平凡的硬件问题上……但希望它对遇到这个问题的其他人有用……

于 2010-02-01T04:40:04.400 回答
1

Android supports 3gp and mp4 format, but still sometimes there are problems in playing an mp4 content. one thing what I have found out from my research is that, this might be because the resolution problem with the video. I think that you should re-size the resolution of your mp4 video. This might help.

于 2011-05-09T04:21:37.750 回答
0

我没有尝试从资源中播放视频剪辑,我不确定它是否有效。

作为测试,将视频剪辑放在 SD 卡上并将其用作视频源。

如果您遇到相同的症状,则可能是 MP4 文件有问题,或者与您的测试环境有关(例如,您使用的是模拟器并且没有四核 CPU)。

但是,如果 SD 卡测试有效,那么我怀疑问题在于将其打包为资源。

于 2010-01-30T15:02:46.100 回答