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.
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.
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.
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.
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.
<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" />
Use exoplayer last version androidx.media3:media3-exoplayer:1.4.0-rc01
This version has image slide support
© 2022 - 2024 — McMap. All rights reserved.