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.
here is simple trick
check the condition media player.getCurrentPosition == 0 in on prepared listener of video view ,black screen will appear when position is zero so display an image untill the video will load
mycode:
That flash comes from changing the current content view to another one. You could try adding a VideoView to your layout xml file then referencing it with
(VideoView) findViewById(R.id.vid);
instead ofnew VideoView(this);
and setting the content view to that layout.Where are you changing the contentView (in which method did you write the four lines of code above)?
You should only set the contentView in the
onCreate()
method of anActivity
. If you are doing it somewhere else (for exemple in a button’s callback), you should start a new activity instead.Try this line.This worked for me. if(player!=null)player.release();
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 whenstopPlayback()
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.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:
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):
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.This now looks awesome on my Galaxy Tab, I don't dare to test it on the SGS2 phone, though...
I ended up having to do something very similar to @tommyd to avoid the black surfaceView flash at the beginning and end of my videos. However, I found that setting/nulling the background drawable for the videoView was not occurring instantly on many phones. There could be about a half-second delay between my call to set the background and when it was actually displayed.
What I ended up doing was creating a custom SurfaceView that showed a single, solid color, then overlayed this on top of the VideoView and made use of SurfaceView.setZOrderMediaOverlay().
My custom SurfaceView was heavily informed by: http://android-er.blogspot.com/2010/05/android-surfaceview.html
And in the parent activity that hosts the views:
You can then do things like
mVideoMask.setVisibility(View.GONE)
to hide the mask ormVideoMask.setVisibility(View.VISIBLE)
to show the mask (and hide the black-screened VideoView).In my experiments on various phones, this method provided very fast showing/hiding of the video mask, as opposed to setting/nulling the background.