how can I Display image in ExoPlayer?
Asked Answered
G

4

8

I have list of URLs mix with videos and images. I want to display both using ExoPlayer. I could display videos in the ExoPlayer, however when I try to display image I am getting a black screen.

Thank you in advance.

Goldarn answered 13/6, 2018 at 5:52 Comment(2)
As per the Exo player developer console, it's mentioned that Exo player only used for the Audio and Video.Hodosh
Add ImageView and Exoplayer in Framelayout. Show Image (That is knows as thumbnails) in imageView and on tap of ImageView Hide it and show ExoPlayer and play it.Bloodstained
T
15

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.

Tacet answered 17/12, 2018 at 18:22 Comment(0)
D
3

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.

Drysalter answered 21/6, 2020 at 16:17 Comment(2)
i wanted to set custom image stored in firebase storage using Glide while playing audio files. The #1 part was the answer i was looking for. ThanksAeriela
Thanks! but my thumbnail is not hiding after the video is playing! its like image above video ! does i miss something?Assiduous
M
1
<com.google.android.exoplayer2.ui.PlayerView
        android:id="@+id/video_player"
        android:layout_width="match_parent"
        android:layout_height="@dimen/_150sdp"
        android:layout_centerInParent="true"
        android:visibility="visible"
        app:default_artwork="@drawable/default_media_artwork"
        app:use_artwork="true"
        app:resize_mode="fixed_width"
        app:show_buffering="when_playing" />
Maurer answered 14/5, 2020 at 10:58 Comment(0)
I
0

Use exoplayer last version androidx.media3:media3-exoplayer:1.4.0-rc01

This version has image slide support

Injunction answered 13/7 at 20:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.