how can I Display image in ExoPlayer?

I use exoplayer-ui:r2.5.4 and SimpleExoPlayerView has built in image view.
you can set your image with default_artwork attribute in xml, for example:

<com.google.android.exoplayer2.ui.SimpleExoPlayerView
    android:id="@+id/playerView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:default_artwork="@drawable/default_media_artwork"
    app:use_artwork="true"/>

Hope to be useful.


When I'm trying to use the ImageView as a thumbnail out of exoplayer2.ui.PlayerView, it's not working as I expected. For example, the thumbnail itself should be placed above the video surface but under the playback controls.

At the same time, all with artwork is just about the audio source. Therefore, the drawable assigned to app:default_artwork does not work for video media source although I set app:use_artwork to true.

Here is the working solution for me.

ExoPlayer library comes with possibility for customizing the player view layout and playback control layout.

You have got two options to implement thumbnail in the playerview.

  1. Create custom layout file named exo_simple_player_view.xml. You can copy the layout content from library. And then add the ImageView within the AspectRatioFrameLayout of @id/exo_content_frame or anywhere else in the layout. Please be careful that your imageview is not covered by any other elements in the layout.

  2. Create custom layout file with custom name. And then link that layout to the PlayerView using app:player_layout_id.

The #1 is for the case that you want to have custom layout for all player views in your app while #2 is just for the case for the single player view on specific page.

Once you created the layout file and linked, you can simply find your image view with the ID and set any drawable, or image url using Glide or so on.