前后打后VideoView黑色闪光 [英] VideoView black flash before and after playing

查看:184
本文介绍了前后打后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>

本活动呈现在全屏和视频(大部分)缩放到整个屏幕大小(1024×600的屏幕,视频960×640)。我说的大多的,因为一些未知的原因布局的背景图像融合,通过约10px的顶部。这是最后的黑客,我不得不申请,使其工作 - 移动视频容器 -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天全站免登陆