VideoView: Fullscreen on doubleTap

房东的猫 提交于 2019-12-10 15:17:31

问题


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


回答1:


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:

  1. Holding the VideoView in a FrameLayout and then changing its layout parameters.
  2. Overlaying the VideoView via Window#addContentView.
  3. Hiding (via Visibility.GONE) your other views and allowing the VideoView to expand its layout area.



回答2:


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.



来源:https://stackoverflow.com/questions/5640025/videoview-fullscreen-on-doubletap

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