3

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>
Andy
  • 751
  • 1
  • 12
  • 25

2 Answers2

0

You can have media controller thumbnail on top of the player view with low opacity and you can manage having video preview thumbnail.

0
  • Your Packager must write an AdaptationSet of mimeType "image" inside your DASH manifest.
  • Then you need to create a custom DashManifestParser() that will grab the "image" AdaptationSet from the DASH manifest.
  • Add this ManifestParser to your MediaSource in order to extract thumbnails urls and positions
KJ Newtown
  • 328
  • 1
  • 16