VideoView播放前后黑闪 [英] VideoView black flash before and after playing

查看:28
本文介绍了VideoView播放前后黑闪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 VideoView,我想用它来播放影片剪辑.我用它来播放它并且它有效.

I have a VideoView which I want to use to play a movieclip. I use it like this to play it and it works.

VideoView vv = new VideoView(this);
vv.setVideoURI(Uri.parse("android.resource://cortex2.hcbj/raw/intro"));
setContentView(vv);
vv.start();

但是我看到影片剪辑前后都有黑色闪光.闪光灯本身不是一个大问题,但它的黑度是.背景是白色的,所以如果闪光灯是白色的,或者它消失了就可以了.

However I see a black flash just before and after the movie clip. The flash in itself isn't a big problem, but the blackness of it is. The background is white, so if the flash is white, or if it dissapears it will be okay.

推荐答案

今天我遇到了同样的问题,并为这个令人讨厌的问题找到了一个非常糟糕和笨拙的解决方法:我意识到可以设置背景颜色/可绘制到 VideoView 混合在视频表面并使其完全隐藏.这仅在底层视频仍在播放时有效,而不是在它停止时(无论是在正常结束时还是在调用 stopPlayback() 时),否则你会再次看到黑色闪烁.背景也不能一开始就设置,否则视频一开始就完全隐藏起来.

Today I had the same problem and found a very bad and hacky workaround for this nasty problem: I realized that one can set a background color / drawable onto the VideoView which blends over the video surface and makes it completely hidden. This only works though while the underlying video is still playing, not when it is stopped (neither when it ended normally nor when stopPlayback() was called), otherwise you'd again see a black flicker. The background must also not be set in the beginning, otherwise the video would be completely hidden right from the start.

所以对我来说唯一合乎逻辑的步骤是在我开始视频之前发布一个延迟事件 - 因为我知道视频长度,我让这个事件在它正常结束前几毫秒发生.我在 VLC 中截取了最后一帧的屏幕截图,然后将其混合如下:

So the only logical step for me was to post a delayed event just before I start the video - and since I know the video length, I let this event happen just a few milliseconds before it ends normally. I took a screenshot of the last frame in VLC and then blended it like this:

private void startVideo()
{
    introVideo.setBackgroundDrawable(null);
    introVideo.postDelayed(new Runnable() {
        public void run()
        {
            if (!introVideo.isPlaying())
                return;

            introVideo.setBackgroundResource(R.drawable.video_still_image);
            // other stuff here, for example a custom transition to
            // another activity
        }
    }, 7500); // the video is roughly 8000ms long
    introVideo.start();
}

然而这还不够,因为当视频真正结束时,我仍然有短暂的黑屏闪烁,所以我还必须将静止图像设置为包含视频的容器的背景(在我的情况下是活动的布局):

This however was not enough, because when the video actually ended, I still got a short black screen flicker, so I also had to set the still image as background of the container that contained the video (in my case it was the layout of the activity):

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:background="@drawable/video_still_image">

    <VideoView android:id="@+id/introVideo"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:layout_alignParentRight="true"
              android:layout_alignParentLeft="true"
              android:layout_alignParentTop="true"
              android:layout_alignParentBottom="true"
              android:layout_marginTop="-10dip" />

</RelativeLayout>

此活动以全屏方式呈现,视频(大部分)缩放到总屏幕尺寸(屏幕 1024x600,视频 960x640).我说大部分,因为由于某种未知的原因,布局的背景图像在顶部混合了大约 10 像素.这是我为使其工作而必须应用的最后一个 hack - 将视频容器 -10dip 移动到顶部的空白处.

This activity is rendered in fullscreen and the video is (mostly) scaled to the total screen size (screen 1024x600, video 960x640). I say mostly, because for some unknown reason the layout's background image blends through for about 10px on top. This was the last hack I had to apply to make it work - move the video container -10dip into the void on top.

现在在我的 Galaxy Tab 上看起来很棒,不过我不敢在 SGS2 手机上测试它...

This now looks awesome on my Galaxy Tab, I don't dare to test it on the SGS2 phone, though...

这篇关于VideoView播放前后黑闪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆