简体   繁体   English

Android播放mp4文件无视频显示

[英]No video display when playing an mp4 file on Android

I try to render an mp4 file I added to my android ressources in res/raw like so:我尝试在res/raw中渲染我添加到我的 android 资源的 mp4 文件,如下所示:

public class Main extends RoboActivity
{
    @InjectView(R.id.introVideo)
    private VideoView introVideo;

    private MediaPlayer player;

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.main);

        player = MediaPlayer.create(this, R.raw.intro_video2);
        SurfaceHolder holder = introVideo.getHolder();
        player.setDisplay(holder);
        player.start();

        player.setOnCompletionListener(new OnCompletionListener() {
            public void onCompletion(MediaPlayer mp)
            {
                startActivity(new Intent(Main.this, Story.class));
                releasePlayer();
            }
        });
    }

    @Override
    protected void onPause()
    {
        super.onPause();
        releasePlayer();
    }

    @Override
    protected void onDestroy()
    {
        super.onDestroy();
        releasePlayer();
    }

    private void releasePlayer()
    {
        if (player != null)
        {
            player.release();
        }
    }
}

but all I experience is the sound of the video, the screen keeps blank on my Samsung GalaxyTab.但我所体验到的只是视频的声音,我的 Samsung GalaxyTab 屏幕一直空白。 The source file is an mp4 file (H.264 AVC, 960x640, 30fps) and can be played perfectly fine with Quicktime and VLC.源文件是一个 mp4 文件(H.264 AVC、960x640、30fps),可以用 Quicktime 和 VLC 完美播放。

I tried to downscale and resize the original video with Handbrake, down to 480x320 and 25fps, I tried several settings in handbrake, everything without success.我尝试使用 Handbrake 缩小和调整原始视频的大小,降低到 480x320 和 25fps,我尝试了 handbrake 中的几种设置,但都没有成功。

Is there anything obviously wrong with my code or is it the video format or something else - what am I doing wrong?我的代码有什么明显的错误,或者是视频格式还是其他什么——我做错了什么?

Thanks in advance, Thomas.提前致谢,托马斯。

I couldn't get the above way to work, but I found that it worked when I solely used the provided functionality of Android's VideoView like this:我无法以上述方式工作,但我发现当我像这样单独使用 Android 的VideoView提供的功能时它可以工作:

...
String videoUri = "android.resource://my.package.path/raw/intro_video";
introVideo.setVideoURI(Uri.parse(videoUri));
introVideo.start();
...

Is it the 10.1v tab (running 3.0 or 3.1) or an "old" one running 2.2?是 10.1v 选项卡(运行 3.0 或 3.1)还是运行 2.2 的“旧”选项卡?

According to this: http://developer.android.com/guide/appendix/media-formats.html you seem to need 3.0+ for H.264 AVC.据此: http://developer.android.com/guide/appendix/media-formats.html你似乎需要 AVC 3.0+ for H.24 I have had troubles with H 264 myself even with recommended values, had to downscale the sound even more.即使使用推荐值,我自己也遇到了 H 264 的问题,不得不进一步缩小声音。 Might be worth looking in to.可能值得关注。

Give MediaPlayer a PreparedListener.给 MediaPlayer 一个 PreparedListener。 And call MediaPlayer.start() in PreparedListener.并在 PreparedListener 中调用 MediaPlayer.start()。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM