在显示带有IMA扩展名和ProgressiveMediaSource的广告时,出现以下错误。前置广告完成后,应用程序崩溃了。
导航到类ImaAdsLoader时,出现错误“库源与ImaAdsLoader类的字节码不匹配”
java.lang.NoSuchMethodError: No virtual method getadGroupIndexAfterPositionUs(J)I in class Lcom/google/android/exoplayer2/source/ads/AdPlaybackState; or its super classes (declaration of 'com.google.android.exoplayer2.source.ads.AdPlaybackState' appears in /data/app/com.example.exomedia-pEwo-P6MjYGRL3PeKbTLiw==/base.apk)
at com.google.android.exoplayer2.ext.ima.ImaAdsLoader.getcontentProgress(ImaAdsLoader.java:758)
at com.google.ads.interactivemedia.v3.internal.iu.a(IMASDK:4)
at com.google.ads.interactivemedia.v3.internal.jh.handleMessage(IMASDK:27)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:193)
at android.app.activityThread.main(activityThread.java:6692)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
重现步骤 :
使用以下依赖度
implementation 'com.google.android.exoplayer:exoplayer-core:2.10.7'
implementation 'com.google.android.exoplayer:exoplayer-ui:2.10.7'
implementation 'com.google.android.exoplayer:extension-ima:2.9.6'
并使用以下代码启动播放:
player=ExoPlayerFactory.newSimpleInstance(this,DefaultTrackSelector())
player_view.player=player
adsLoader?.setPlayer(player)
val dataSourceFactory = DefaultDataSourceFactory(
this,"ExoDemo")
val mediaSource:MediaSource=ProgressiveMediaSource.Factory(dataSourceFactory)
.createMediaSource(Uri.parse(resources.getString(R.string.media_url_mp4)))
val adsMediaSource = AdsMediaSource(mediaSource,dataSourceFactory,adsLoader,player_view)
player?.prepare(adsMediaSource)
player?.setPlayWhenReady(true)
使用以下版本的库并使用ExtractorMediaSource可以正常工作:
implementation 'com.google.android.exoplayer:exoplayer-core:2.9.6'
implementation 'com.google.android.exoplayer:exoplayer-ui:2.9.6'
implementation 'com.google.android.exoplayer:extension-ima:2.9.6'