我目前正在 Android 应用程序中从 ExoPlayer(com.google.android.exoplayer2 版本 2.19.1)迁移到 Media3 (1.1.1)。我已按照中提供的迁移说明进行操作 Android 官方文档.
我已经进行了必要的代码和依赖项更改,但在 XML 布局中膨胀 androidx.media3.ui.PlayerView 时遇到错误。具体来说,我收到以下错误:
android.view.InflateException: Binary XML file line #16 in
com.xxx.xx:layout/mpeg_player: Binary XML file line #16 in
com.xxxx.xx:layout/mpeg_player: Error inflating class
androidx.media3.ui.PlayerView
还有更多
Caused by: android.view.InflateException: Binary XML
file line #78 in com.xxx.xx:layout/exo_player_control_view:
Binary XML file line #78 in com.xxx.xx:layout/exo_player_control_view:
Error inflating class com.google.android.exoplayer2.ui.DefaultTimeBar
Caused by: android.view.InflateException: Binary XML file line #78 in com.xxx.xxx:layout/exo_player_control_view: Error inflating class com.google.android.exoplayer2.ui.DefaultTimeBar
Caused by: java.lang.ClassNotFoundException: com.google.android.exoplayer2.ui.DefaultTimeBar
这是我的xml
<androidx.media3.ui.PlayerView
android:id="@+id/video_view"
app:show_buffering="always"
app:show_subtitle_button="true"
android:focusable="false"
app:use_controller="true"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
并添加了所有依赖项
implementation 'androidx.media3:media3-exoplayer:1.1.1'
implementation 'androidx.media3:media3-exoplayer-dash:1.1.1'
implementation 'androidx.media3:media3-ui:1.1.1'
implementation "androidx.media3:media3-session:1.1.1"
还将其添加到我的 build.gradle 中
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
如果您能提供有关如何解决此问题并成功迁移到 Media3 的任何指导或建议,我将不胜感激。谢谢!
看起来您仍在其中一种布局中使用
com.google.android.exoplayer2.ui.DefaultTimeBar
。
那么,您可以尝试在 app.gradle 文件的依赖项部分添加
implementation 'com.google.android.exoplayer:exoplayer-ui:2.19.1
吗?然后同步并再次尝试构建。