我正在使用android音频应用程序。 该应用程序运行正常,但有时会随机抛出IllegalStateException。
Fatal Exception: java.lang.IllegalStateException
com.google.android.exoplayer2.util.Assertions.checkState (Assertions.java:81)
com.google.android.exoplayer2.upstream.Loader$LoadTask.start (Loader.java:338)
com.google.android.exoplayer2.upstream.Loader$LoadTask.handleMessage (Loader.java:468)
android.os.Handler.dispatchMessage (Handler.java:102)
android.os.Looper.loop (Looper.java:148)
android.os.HandlerThread.run (HandlerThread.java:61)
从堆栈跟踪中,我猜它在加载失败时会抛出,但是我无法复制并且不知道原因。
我的代码是这样的。
val userAgent = WebView(mainService).settings.userAgentString
val dsf = DefaultDataSourceFactory(mainService, userAgent, eventWrapper)
val uri = Uri.fromFile(file)
var defaultExtractorsFactory: DefaultExtractorsFactory? = null
if (file.path.toUpperCase(Locale.US).endsWith("AAC")) {
defaultExtractorsFactory = DefaultExtractorsFactory()
defaultExtractorsFactory.setConstantBitrateSeekingEnabled(true)
}
val mediaSource = ProgressiveMediaSource.Factory(dsf, defaultExtractorsFactory)
.createMediaSource(uri)
player?.playWhenReady = false
val trackSelector = DefaultTrackSelector(AdaptiveTrackSelection.Factory())
player = ExoPlayerFactory.newSimpleInstance(service, trackSelector).apply {
val audioAttributes = AudioAttributes.Builder()
.setUsage(C.USAGE_MEDIA)
.setContentType(C.CONTENT_TYPE_MOVIE)
.build()
setAudioAttributes(audioAttributes, true)
}
player!!.addListener(eventWrapper)
player.prepare(mediaSource)
player.playWhenReady = true
依赖性;
def exo_ver = "2.10.2"
implementation "com.google.android.exoplayer:exoplayer-core:$exo_ver"
implementation "com.google.android.exoplayer:exoplayer-hls:$exo_ver"
我的代码有问题吗? 预先谢谢你。