Exoplayer builder 在按下并再次打开视频时出错

Exoplayer builder gives error when back pressed and open video again

我正在使用 ExoPlayer 播放视频。一切正常,工作正常,直到 pressing.I 我正在使用回收站视图。用户按下一个项目以输入 video.But 当用户按下并再次打开另一个视频或同一视频时,播放器生成器给出以下错误。我从来没有在网上看到过关于这个的解决方案。而且我还需要说明,我在文档中使用了相同的生成器方法。

这是错误:

Process: com.example.exoplayer, PID: 19208
   java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/exoplayer2/source/ads/AdsMediaSource$MediaSourceFactory;
       at java.lang.Class.classForName(Native Method)
       at java.lang.Class.forName(Class.java:453)
       at java.lang.Class.forName(Class.java:378)
       at com.google.android.exoplayer2.source.DefaultMediaSourceFactory.loadDelegates(DefaultMediaSourceFactory.java:321)
       at com.google.android.exoplayer2.source.DefaultMediaSourceFactory.<init>(DefaultMediaSourceFactory.java:152)
       at com.google.android.exoplayer2.source.DefaultMediaSourceFactory.<init>(DefaultMediaSourceFactory.java:127)
       at com.google.android.exoplayer2.SimpleExoPlayer$Builder.<init>(SimpleExoPlayer.java:195)
       at com.google.android.exoplayer2.SimpleExoPlayer$Builder.<init>(SimpleExoPlayer.java:153)
       at com.example.exoplayer.MainActivity.initializePlayer(MainActivity.kt:193)
       at com.example.exoplayer.MainActivity.onStart(MainActivity.kt:70)
       at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1333)
       at android.app.Activity.performStart(Activity.java:6992)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2780)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
       at android.app.ActivityThread.-wrap11(Unknown Source:0)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
       at android.os.Handler.dispatchMessage(Handler.java:105)
       at android.os.Looper.loop(Looper.java:164)
       at android.app.ActivityThread.main(ActivityThread.java:6541)
       at java.lang.reflect.Method.invoke(Native Method)
       at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
    Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.exoplayer2.source.ads.AdsMediaSource$MediaSourceFactory" on path: DexPathList[[zip file "/data/app/com.example.exoplayer-V2UiSJoFtK6lpPhAy-YB-g==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.exoplayer-V2UiSJoFtK6lpPhAy-YB-g==/lib/x86, /system/lib, /vendor/lib]]
       at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93)
       at java.lang.ClassLoader.loadClass(ClassLoader.java:379)

这是我的初始化和释放方法:

初始化()

   private fun initializePlayerXml(currentXmlLink: String) {
       if (player == null) {
           val trackSelector = DefaultTrackSelector(this)
           trackSelector.setParameters(
               trackSelector.buildUponParameters().setMaxVideoSizeSd()
           )
           player = SimpleExoPlayer.Builder(this)
               .setTrackSelector(trackSelector)
               .build()

       }
       if (player!!.bufferedPosition == 0L) {
           playButton.setImageResource(R.drawable.ic_pause)
       }

       playButton.setOnClickListener {
           if (player!!.isPlaying) {
               player!!.pause()
               playButton.setImageResource(R.drawable.ic_play)
           } else {
               player!!.play()
               playButton.setImageResource(R.drawable.ic_pause)
           }


       }
       val doubleClickForwardFun = DoubleClick(object : DoubleClickListener {
           override fun onSingleClickEvent(view: View?) {

           }

           override fun onDoubleClickEvent(view: View?) {
               val currentPosition = player!!.currentPosition
               player!!.seekTo(currentPosition + 10000)
           }
       })

       val doubleClickBackwardFun = DoubleClick(object : DoubleClickListener {
           override fun onSingleClickEvent(view: View?) {

           }

           override fun onDoubleClickEvent(view: View?) {
               val currentPosition = player!!.currentPosition
               player!!.seekTo(currentPosition - 10000)
           }
       })


       forwardButton.setOnClickListener {
           val currentPosition = player!!.currentPosition
           player!!.seekTo(currentPosition + 10000)
       }
       backwardButton.setOnClickListener {
           val currentPosition = player!!.currentPosition
           player!!.seekTo(currentPosition - 10000)

       }
       doubleClickBackward.setOnClickListener(doubleClickBackwardFun)
       doubleClickForward.setOnClickListener(doubleClickForwardFun)

       val mediaItem =
           MediaItem.Builder()
               .setUri(currentXmlLink)
               .setMimeType(MimeTypes.APPLICATION_MPD)
               .build()
       player!!.addMediaItem(mediaItem)
       player!!.addMediaItem(mediaItem)

       playerView!!.player = player
       player!!.playWhenReady = playWhenReady
       player!!.seekTo(currentWindow, playbackPosition)
       playbackStateListener.let { player!!.addListener(it) }
       player!!.prepare()
   }

发布()


   private fun releasePlayer() {
       if (player != null) {
           player!!.removeListener(playbackStateListener)
           player!!.release()
           player!!.stop()
           player = null
       }
   }

我刚发现使用不同版本的exoplayer时会出现solution.The问题。我正在使用这些来解决问题。

    implementation 'com.google.android.exoplayer:exoplayer:2.12.1'
    implementation 'com.google.android.exoplayer:exoplayer-core:2.12.1'
    implementation 'com.google.android.exoplayer:exoplayer-dash:2.12.1'
    implementation 'com.google.android.exoplayer:exoplayer-ui:2.12.1'
    implementation 'com.google.android.exoplayer:exoplayer-hls:2.12.1'

有关详细信息,请查看我在 Github here 上的问题。