Issue displaying thumbnail image in VideoView

天涯浪子 提交于 2019-12-07 13:00:08

问题


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.


回答1:


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!




回答2:


Use this code

BitmapDrawable bitmapDrawable = new BitmapDrawable(bitmapImage);
            videoview.setBackgroundDrawable(bitmapDrawable);
        videoview.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                public void onPrepared(MediaPlayer mp) {

                    videoview.setBackgroundDrawable(null);
                }
            });


来源:https://stackoverflow.com/questions/8235251/issue-displaying-thumbnail-image-in-videoview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!