The accepted answer for avoiding the black flicker on VideoView is to do something like the following. This works great, in fact it's smooth and I can reset the video, change the file and everything without a flicker.
Now...How can I draw a View on top of the VideoView?
mVideoView.setZOrderMediaOverlay(true);
mVideoView.setZOrderOnTop(true);
The order of the view on the layout makes no difference at all, since we are calling those methods. I would love to show you guys a screenshot of what's going on but it's simply drawing the video over the other views.
Hate answering my own questions but here it goes:
The least painful way of doing this is actually to avoid using a VideoView and resulting to the use of a TextureView and playing the video in its surface. That way it doesn't necessarily try to be on top of everything but still allows us to draw things over it.
Related
I've been using SurfaceView and Canvas to draw Bitmaps to the screen. I've been looking into using videos to speed up some animation, but drawing Bitmaps and playing videos are two different things. Is it possible to draw both Bitmaps and videos to the screen? According to this post it doesn't sound possible, but maybe there's another way?
The last comment in there seems to indicate that he got it working. Instead of trying to layer a VideoView and your SurfaceView you are going to have to make yourself a MediaPlayer and set it up to play on a designated portion of the SurfaceView that you already have. VideoView is made up of a MediaPlayer and a SurfaceView, and you are disallowed from stacking two SurfaceViews.
That link to the api demos in the last comment from your question shows you how you "tie together" a SurfaceView and a MediaPlayer to make it show a video file.
I am currently attempting to animate some images in my SurfaceView. Right now, I am displaying my images as Bitmaps. However, I think it might be better to implement these Bitmaps as ImageViews. I have not been able to create multiple ImageViews on my SurfaceView (I am trying to not do this in XML, as I want to get things working first and then later change things around so it is more portable). Is there a tutorial somewhere on how to do this, or am I like wayyy off and should just stick to Bitmaps??
You generally shouldn't try to mix View objects and SurfaceView. SurfaceView is a very special view that provides direct drawing by essentially punching a hole in the current window. It seems better to stick to bitmaps.
We've noticed that when you put Android views with view animation (nothing complex, just AlphaAnimation and TranslateAnimation) on top of a GLSurfaceView, the animation runs slowly (i.e. you see a lot of stuttering.) I am calling pause() on the GLSurfaceView, and I believe I've confirmed (through setting breakpoints) that the GL draw calls are not getting hit while the animation is playing, so I'm not sure where the slowness is coming from.
Does anyone know of a way around this? I know that on iPhone this also used to be a problem, but there was some OS update they made to fix the issue. They are short view animations (e.g. You Win!) so it's not the worst thing in the world, but it would be nice if there was some workaround.
The reason we are not doing the animations in GL is that they have to be able to run from any Activity in our game, and not all of our Activities have GLSurfaceViews.
Finally, if it matters, we am using the modified GLSurfaceView source from Replica Island http://code.google.com/p/replicaisland/
Drawing on top of a GLSurfaceView is slow, therefore animating is as well. You are forcing the framework to do more work to determine what part of the surface view is visible.
You should really consider doing these animations inside the surface view when you are using a surface view.
An alternative is to put the animation in a small window above your activity.
I have a video, and I need to get some of its frames.
I used to do the following: Create a standart bitmap with the size of the video in question, create a canvas and set it to draw on a bitmap.
I use a SurfaceView and a surfaceHolder. A mediaPlayer is drawing on the surfaceView, and I have a method that calls surfaceView.draw(canvas), which draws on the canvas, which draws to the bitmap, which I eventually take and use...
My problem is that 60% of the time I get black frames. The mediaplayer plays its content in a separete thread, and I do not know when the video has started, and when - not, so I believe this is what is getting my black screens.
I need a workaround, a fix, or another method to get the video frame.
Thanks in advance.
You might try looking at the source of the gallery app or wherever its video thumbnails come from if they are externally created
How about using MediaMetadataRetriever's getFrameAtTime(). For lower API versions use this
I currently have an app with a regular layout of buttons and widgets. On top of this I'd like to draw some animated sparks and particles and whatnot going on in response to events, so I've got it in a FrameLayout with another View on top to draw the animations. The problem is I can't work out a way of getting smooth movement out of it. I've tried a few options:
SurfaceView: because of the way it takes over the screen, you can't see anything behind a SurfaceView so the background is fully black.
Override View.onDraw and call invalidate(): this almost works, but invalidate isn't a very reliable way of getting a redraw to happen soon, so the motion is very jerky.
Animation framework: Testing with TranslateAnimation, it seems a bit smoother than using onDraw(), but animations are designed to run for a specific duration and I want to draw indefinitely.
Anybody know any tricks to make one of these work properly, or something completely different?