I'm using VideoView for a web video, and I also have a bitmap object contains the corresponding thumbnail image. Now how should I set the bitmap to the VideoView for displaying the thumnail?
I'm using
videoView.setBackgroundDrawable(new BitmapDrawable(getResources(), bitmap));
But then when I play this video, the video doesn't show, instead it always show this static thumbnail image.
Any hints would be appreciated. Thanks.
VideoView is a subclass of SurfaceView, which has some special behaviors in terms of its display. SurfaceView contents are actually drawn in a window underneath the view hierarchy and the view simply acts as a hole in the current window so the contents are visible. Because of this, if you apply anything to the view itself (like a background), it will actually be Z-Ordered on top of the video content. In addition, if you place anything underneath the VideoView, it also will not be visible because of this "hole".
If you want to display content in this space while the video is not playing, it will either need to be in a separate View laid out on top of the VideoView that you can hide/show when the video playback state changes, or you need to set/clear the background image you have set when the video playback state changes.
HTH!
Use this code
BitmapDrawable bitmapDrawable = new BitmapDrawable(bitmapImage);
videoview.setBackgroundDrawable(bitmapDrawable);
videoview.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
videoview.setBackgroundDrawable(null);
}
});
Related
I have a FrameLayout with a TextView, ImageView, CCGameView and a VideoView. In the game view I have a simple sprite and label. I have one video playing in the VideoView and one Image in the ImageView.
When the application first starts the image and video are displayed properly but as soon as the gameview loads the video can no longer be seen.
I even tried doing a bringToFront() on the VideoView after the GameView has loaded, in case it was a z order issue, but nothing.
Can anyone help or have any suggestions on how to troubleshoot?
I am going to answer my own question just in case it helps someone else. I put the video view before the CCGameView in the FrameLayout. However the ImageView and TextView I have in the layout are added after the CCGameView. With this order the Gameview is in the background.
I am using a mediaplayer on surfaceview and playing a video file. I dont want the video to be displayed but audio must be audible. Seen some of the questions and tried them, no help. Somebody please help.
Use a RelativeLayout and put an ImageView (with match_parent for width and height) above the SurfaceView in your layout. Set the source for the ImageView to a thumbnail and let the video play behind it (but not visible to the user).
Is there any way to put a VideoView (which plays an MP4 file) above an image (which is the background of my app) ?
In other words, is there any way to put some transparency on my VideoView in the aim that the image be visible through the VideoView ?
Every time I try to put a VideoView over an ImageView, the VideoView hides a part of this ImageView (I tried to put an alpha on my VideoView but it doesn't work).
Basically, what I want to do in my application is displaying a video.
The best tool to achieve this goal seem to be a VideoView.
So I used this code:
<VideoView android:id="#+id/videoview" android:layout_width="50dip" android:layout_height="50dip"></VideoView>
and in my Activity:
VideoView videoHolder = (VideoView)findViewById(R.id.videoview);
videoHolder.setMediaController(new MediaController(this));
videoHolder.setVideoURI(Uri.parse("android.resource://com.blabla.blabla/" + R.raw.blabla));
videoHolder.requestFocus();
videoHolder.start();
and that do the trick.
Unfortunately, I was expecting having a preview (thumbnail) of the video in my layout by default
So , I removed the videoHolder.start(); command, but I can only get a blackscreen. The video start when tapping on an invisible zone...
First question
Is that possible to display a preview of the video in the VideoView before starting it?
Second question
I wuld like to display the video on Fullscreen when double tapping the webview, How can I achieve this?
Thank a lot for any help / link / suggestion
Yes, you can get video thumbnails using ThumbnailUtils:
Bitmap thumb = ThumbnailUtils.createVideoThumbnail(path,
MediaStore.Images.Thumbnails.MINI_KIND);
I haven't really seen apps toggle into fullscreen before. I'm actually not sure if it can be done (especially for a VideoView). However, you might have some luck with one of these methods:
Holding the VideoView in a FrameLayout and then changing its layout parameters.
Overlaying the VideoView via Window#addContentView.
Hiding (via Visibility.GONE) your other views and allowing the VideoView to expand its layout area.
You can use VideoView.seekTo(milliseconds) as an alternative, let say 1 second (1000 milliseconds). Provided that the video clip after 1 second does have an image, like some videos starts from blank screen then "fade-in" (lack of better word) to a scene would more often gives you a black screen with 1 second. You can call this under VideoView.onPrepared(). This one i use when the video is on a web server.
I am having a VideoView in my application.
I have set blur flags in my activity
getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
The problem is even the video in the VideoView is blurring, which I don't want.
When VideoView is replaced by an ImageView with a specified source, its not blurry at all.
Is there any solution to avoid this blur in VideoView?
That's because a VideoView creates a surface behind your application's surface. The FLAG_BLUR_BEHIND flag blurs all the surfaces under your application's surface. This is why the ImageView is not blurry because it is in your application's surface, not in a surface behind it.