Android-如何在带有uri源的VideoView上设置缩略图? [英] Android - how to set a thumbnail on a VideoView with a uri source?

查看:117
本文介绍了Android-如何在带有uri源的VideoView上设置缩略图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

加载时,我需要将一个图像从uri导入到我的VideoView中.当播放时,它应该消失并开始播放视频.这是我的VideoView代码-

I need to get an image from a uri into my VideoView when it loads. It should disappear and start playing the video when play is hit. This is my VideoView code -

<RelativeLayout
    android:id="@+id/video_frame"
    android:layout_width="fill_parent"
    android:layout_height="300dp"
    android:background="#000"
    >

    <VideoView
        android:id="@+id/video"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerInParent="true"
        />

    <ImageButton
        android:id="@+id/play_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:src="@drawable/ic_media_play"
        />

</RelativeLayout>

这就是我的用法-

final VideoView video = (VideoView) convertView.findViewById(R.id.video);

    Uri uri = Uri.parse(submission.getUrl());
    video.setVideoURI(uri);

    final ImageButton playButton = (ImageButton) convertView.findViewById(R.id.play_button);
    video.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
        @Override
        public void onCompletion(MediaPlayer mp) {
            playButton.setVisibility(View.VISIBLE);
        }
    });
    playButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            if (video.isPlaying()){
            }else{
                video.start();
                playButton.setVisibility(View.GONE);
            }
        }

    });

推荐答案

创建视频缩略图,并将其显示在ImageView上.如果需要显示播放按钮,则需要另一个ImageView(带有播放"按钮图标).单击播放"图标图像视图后,即可在VideoView上播放视频.

Create a thumpnail of video and show it on ImageView. In case you need to show play button you need another ImageView (with Play button icon). On click of Play icon image view play the video on VideoView.

    imageView.setImageBitmap(ThumbnailUtils.createVideoThumbnail(urlPath, 
    MediaStore.Video.Thumbnails.MICRO_KIND));

这篇关于Android-如何在带有uri源的VideoView上设置缩略图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆