我得到了一个AudioSources的播放列表,其中包含一些坏的url(返回400错误与一些信息)。我使用ConcatenatingAudioSource来包装那些音频并传递给setAudioSource。
当播放器播放错误的url音频源时,它会抛出如下内容:
E/ExoPlayerImplInternal(10255): Playback error
E/ExoPlayerImplInternal(10255): com.google.android.exoplayer2.ExoPlaybackException: Source error
E/ExoPlayerImplInternal(10255): at com.google.android.exoplayer2.ExoPlayerImplInternal.handleIoException(ExoPlayerImplInternal.java:624)
E/ExoPlayerImplInternal(10255): at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:596)
E/ExoPlayerImplInternal(10255): at android.os.Handler.dispatchMessage(Handler.java:103)
E/ExoPlayerImplInternal(10255): at android.os.Looper.loop(Looper.java:214)
E/ExoPlayerImplInternal(10255): at android.os.HandlerThread.run(HandlerThread.java:67)
E/ExoPlayerImplInternal(10255): Caused by: com.google.android.exoplayer2.upstream.HttpDataSource$InvalidResponseCodeException: Response code: 400
E/ExoPlayerImplInternal(10255): at com.google.android.exoplayer2.upstream.DefaultHttpDataSource.open(DefaultHttpDataSource.java:389)
E/ExoPlayerImplInternal(10255): at com.google.android.exoplayer2.upstream.DefaultDataSource.open(DefaultDataSource.java:201)
E/ExoPlayerImplInternal(10255): at com.google.android.exoplayer2.upstream.StatsDataSource.open(StatsDataSource.java:84)
E/ExoPlayerImplInternal(10255): at com.google.android.exoplayer2.source.ProgressiveMediaPeriod$ExtractingLoadable.load(ProgressiveMediaPeriod.java:1014)
E/ExoPlayerImplInternal(10255): at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:409)
E/ExoPlayerImplInternal(10255): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
E/ExoPlayerImplInternal(10255): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
E/ExoPlayerImplInternal(10255): at java.lang.Thread.run(Thread.java:919)
E/AudioPlayer(10255): TYPE_SOURCE: Response code: 400
在这种情况下我如何捕获错误?
到目前为止我想抓住的是:
audioPlayer.playbackEventStream.listen(
(event) {},
onError: (Object e, StackTrace stackTrace) {
print('A stream error occurred: $e');
},
);
audioPlayer.sequenceStream.listen((event) {},
onError: (Object e, StackTrace stackTrace) {
print('A sequence error occurred: $e');
});
audioPlayer.sequenceStateStream.listen((event) {},
onError: (Object e, StackTrace stackTrace) {
print('A sequencestate error occurred: $e');
});
audioPlayer.processingStateStream.listen((event) {},
onError: (Object e, StackTrace stackTrace) {
print('A processingState error occurred: $e');
});
audioPlayer.playerStateStream.listen((event) {},
onError: (Object e, StackTrace stackTrace) {
print('A playerStateStream error occurred: $e');
});
audioPlayer.playingStream.listen((event) {},
onError: (Object e, StackTrace stackTrace) {
print('A playingStream error occurred: $e');
});
audioPlayer.bufferedPositionStream.listen((event) {},
onError: (Object e, StackTrace stackTrace) {
print('A bufferedPositionStream error occurred: $e');
});
try {
await audioPlayer
.setAudioSource(_playlist, preload: true)
.onError((e, stackTrace) {
print('A player error occurred: $e');
});
} catch (e) {
print("Error loading playlist occurred: $e");
}
尝试播放并捕获如下错误:
try {
// Playback
} on Exception catch (_) {
// Error handling
}