首页 > 解决方案 > How display thumbnail image in Exoplayer video?

问题描述

I want to assign a preview image of the video from a URL. After pressing Play, it should disappear and show the video. I have searched for info but I have not found anything, please if anyone has any more extensive information on the subject. Thank you!

My code:

val mPlayer: SimpleExoPlayer
val inflater = activity?.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
val contenedor: View = inflater.inflate(R.layout.nota_exoplayer_container, null)
val playerView: PlayerView = contenedor.findViewById(R.id.exoPlayer)
playerView.useController = true
playerView.requestFocus()

val bandwidthMeter: BandwidthMeter = DefaultBandwidthMeter()
val videoTrackSelectionFactory: TrackSelection.Factory = AdaptiveTrackSelection.Factory(bandwidthMeter)
val trackSelector: TrackSelector = DefaultTrackSelector(videoTrackSelectionFactory)
mPlayer = ExoPlayerFactory.newSimpleInstance(activity.applicationContext, trackSelector)

playerView.player = mPlayer
val fullScreenBtn = playerView.findViewById<ImageView>(R.id.exo_fullscreen_icon)

val defaultBandwidthMeter = DefaultBandwidthMeter()
val dataSourceFactory: DataSource.Factory = DefaultDataSourceFactory(
        activity.applicationContext,
        Util.getUserAgent(activity.applicationContext, "VID"),
        defaultBandwidthMeter)

val mediaSource = ExtractorMediaSource.Factory(dataSourceFactory).createMediaSource(Uri.parse(url))
mPlayer.prepare(mediaSource)

My layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/exoContainer"
    android:orientation="vertical"
    style="@style/ajustar_al_padre">

    <com.google.android.exoplayer2.ui.PlayerView
        android:id="@+id/exoPlayer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
</LinearLayout>

标签: androidkotlinexoplayer2.xvideo-thumbnails

解决方案


  • 您的打包程序必须在您的 DASH 清单中写入 mimeType“图像”的 AdaptationSet。
  • 然后,您需要创建一个自定义 DashManifestParser(),它将从 DASH 清单中获取“图像”AdaptationSet。
  • 将此 ManifestParser 添加到您的 MediaSource 以提取缩略图 url 和位置

推荐阅读