Is it Possible to Use Both Video and Bitmaps? - android

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.

Related

Drawing over a videoView after calling setZOrderOnTop(true)

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.

How to get FPS of the video played by MediaPlayer when using a SurfaceView?

I am using MediaPlayer to play video which can be zommed in and out and am trying to see if there is any difference in the performance between using a SurfaceView and a TextureView for the player's output.
For the TextureView, I used SurfaceTextureListener.onSurfaceTextureUpdated() to know when a frame is shown and thus compute the FPS.
However, I can't find a way to do something similar when using a SurfaceView. I tried creating my own class extending SurfaceView and overloading onDraw(), but it looks like onDraw() is never called when playing the movie.
Any idea if and how this can be achieved?

Display ImageView in SurfaceView

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.

Handling two surfaceViews

I have two surface Views
1> MediaRecorder display surfaceview.
2> MediaPlayer SurfaceView displaying the Media recorded by MediaRecorder.
I want to display both the views simultaneously on the screen z ordered.
The mediaPlayer will be palying in full screen and the MediaRecorderPreview shd appear in the top right corner with some smaller size.
I am able to do this using two surfaces but the issue is that the MediaRecorder Preview always goes to the background z order and gets hidden by the mediaplayer full screen display.
Is their any way to define the Z order of Surface View.
Or is their any other suzzestion i can do to make this work. Can i start both MediaRecorder and MediaPlayer in a single surface?
Pls suggest. Thanks!!
I want to display both the views simultaneously on the screen z ordered.
AFAIK, that is not supported by Android. Android cannot composite multiple SurfaceViews. It can handle a regular View (e.g., Button) on top of a SurfaceView, but not two SurfaceViews Z ordered.
I recommend redesigning your application to have a single SurfaceView at a time.
As of Android 2 (API level 5) having 2 surfaceviews is supported. You can set the zOrder of the 2 surface views using setZOrderMediaOverlay although apparently it breaks the intended semantics of SurfaceView.

Android::get a frame of a Video?

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

Categories

Resources