在ExoPlayer中,我如何在加载媒体源并寻求位置而不是空白后显示第一帧的缩略图?



如何显示片段恢复后视频的第一帧,而不是视频播放器是空白的?

1。添加surface_type ="texture_view"toPlayerView

<com.google.android.exoplayer2.ui.PlayerView
android:id="@+id/player_view"
app:surface_type="texture_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />

2)。在布局

的PlayerView前面添加缩略图视图
<View
android:id="@+id/view_thumbnail_background"
android:visibility="invisible"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black" />
<ImageView
android:id="@+id/image_thumbnail"
android:visibility="invisible"
android:layout_width="match_parent"
android:layout_height="match_parent" />

3)。创建一个方法从TextureView

中获取Bitmap
private fun setVideoThumbnail() {
val textureView = playerView.videoSurfaceView as TextureView
val bitmap = textureView.bitmap
thumbnailImage.setImageBitmap(bitmap)
thumbnailBackground.visibility = View.VISIBLE
thumbnailImage.visibility = View.VISIBLE
}

4)。InonPausecall

setVideoThumbnail()
// destroy player or not depending

5)。为onViewCreated中的thumbnailImage添加onClick监听器

thumbnailImage.setOnClickListener {
// make sure player is re-created and media source is loaded, prepared, and seekTo
player.playWhenReady = true
thumbnailBackground.visibility = View.INVISIBLE
thumbnailImage.visibility = View.INVISIBLE
}

相关内容

  • 没有找到相关文章

最新更新