如何在 ExoPlayer 中显示图像?

how can I Display image in ExoPlayer?

我有混合视频和图片的 URL 列表。我想使用 ExoPlayer 显示两者。我可以在 ExoPlayer 中显示视频,但是当我尝试显示图像时出现黑屏。

提前致谢。

我使用 exoplayer-ui:r2.5.4 并且 SimpleExoPlayerView 在图像视图中有 built。
您可以使用 default_artwork 属性在xml,例如:

<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"/>

希望对你有用

<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" />

当我尝试将 ImageView 用作 exoplayer2.ui.PlayerView 中的缩略图时,它没有像我预期的那样工作。例如,缩略图本身应放置在视频表面上方但在播放控件下方。

同时,所有带artwork的只是音源。因此,尽管我将 app:use_artwork 设置为 true

,但分配给 app:default_artwork 的可绘制对象不适用于视频媒体源

这是对我来说可行的解决方案

ExoPlayer 库可以自定义 player view layout and playback control layout

您有两个选项可以在播放器视图中实现缩略图。

  1. 创建名为 exo_simple_player_view.xml 的自定义布局文件。您可以从库中复制布局内容。然后在 @id/exo_content_frameAspectRatioFrameLayout 或布局中的任何其他位置添加 ImageView。请注意您的 imageview 未被布局中的任何其他元素覆盖。

  2. 使用自定义名称创建自定义布局文件。然后 link 使用 app:player_layout_id.

    该布局到 PlayerView

#1 适用于您希望为应用中的所有播放器视图自定义布局的情况,而 #2 仅适用于特定页面上的单个播放器视图的情况。

创建布局文件并 link 编辑后,您可以简单地找到带有 ID 的图像视图并使用 Glide 等设置任何可绘制对象或图像 url。