Android 无法播放视频 .mp4

发布于 2024-08-19 08:19:30 字数 715 浏览 4 评论 0原文

我准备了一个代码来播放 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();
    }
}

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

I have prepared a code to just play a simple mp4 file from my res folder. The coding is something like this:

    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();
    }
}

Now though there is no error in playing. The activity automatically generates a dialog saying "sorry this video cannot be played", but I can hear the audio and it plays till end. What is the problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

复古式 2024-08-26 08:19:30

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

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

很抱歉在普通的硬件问题上浪费了您宝贵的时间...但希望它对遇到此问题的其他人有用...

Thanx a lot commonsware.com... but i found the solution to the problem... And astonishingly its the PC processor which is the culprit... I checked n a higher configuration and guess wat... it worked perfectly fine... though sometimes if we do some processing in the background the dialog box does come up but on clicking ok it starts playing the video after some time...

But i confirm that this technique of playing file from resource is ok as far as i know...

sorry to waste ur precious time in a mundane hardware problem... but hope it'll be useful for other people who get this problem...

木有鱼丸 2024-08-26 08:19:30

Android支持3gp和mp4格式,但有时在播放mp4内容时仍然会出现问题。
我从研究中发现的一件事是,这可能是因为视频的分辨率问题。
我认为你应该重新调整 mp4 视频的分辨率。这可能会有所帮助。

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.

只是偏爱你 2024-08-26 08:19:30

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

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

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

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

I have not attempted to play a video clip out of a resource, and I am not certain that it works.

As a test, put the video clip on the SD card and use that as the source of your video.

If you get the same symptoms, then either the MP4 file has issues or it is something with your test environment (e.g., you are using the emulator and don't have a quad-core CPU).

If the SD card test works, though, then I suspect the problem is packaging it as a resource.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文