首页 > 解决方案 > 如何防止错误膨胀类 com.google.android.exoplayer2.ui.PlayerView?

问题描述

Exoplayer2 在三星、Vivo、小米等设备上的发布和调试版本都运行良好。但是当我在 Play 商店上发布我的应用程序时,它会在一些设备上抛出错误,比如 nexus、像素手机。

Crashlytics showing this error: Caused by android.view.InflateException: 
Binary XML file line #11: Error inflating class com.google.android.exoplayer2.ui.PlayerView

我发现已经针对同一问题提出了一些类似的问题,但对我没有任何用处。(我使用的是没有任何自定义的默认播放器)有人可以帮我解决这个问题吗?

我的代码:

<com.google.android.exoplayer2.ui.PlayerView
      android:id="@+id/playerView"
      android:focusable="true"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
  />


 var player:SimpleExoPlayer?=null


  override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.pdf_view_normal)

       player = ExoPlayerFactory.newSimpleInstance(this)
       val mediaDataSourceFactory = DefaultDataSourceFactory(this, getUserAgent(this, "demo.smart.com"))

      val mediaSource = ProgressiveMediaSource.Factory(mediaDataSourceFactory)
                                        .createMediaSource(Uri.parse(""))

        with(player) {
               this!!.prepare(mediaSource, false, false)
               playWhenReady = true
                     }

        playerView.setShutterBackgroundColor(Color.TRANSPARENT)
        playerView.player = player
        playerView.requestFocus()

}


override fun onDestroy() {
     super.onDestroy()

        if(player!=null){
                player!!.stop()
         }
 }

摇篮

android{
   
    kotlinOptions {
        jvmTarget = "1.8"
    }
    ..

}


 implementation 'com.google.android.exoplayer:exoplayer:2.10.8'
 

所有日志供您参考

Fatal Exception: java.lang.RuntimeException
Unable to start activity ComponentInfo{demo.smart.com.Viewer}: android.view.InflateException: Binary XML file line #11: Binary XML file line #11: Error inflating class com.google.android.exoplayer2.ui.PlayerView

Caused by android.view.InflateException
Binary XML file line #11: Binary XML file line #11: Error inflating class com.google.android.exoplayer2.ui.PlayerView

标签: androidcrashexoplayer2.xinflate-exceptioninvocationtargetexception

解决方案


推荐阅读