如何捕获音频文件 url 问题?
How to catch an audio file url issue?
我将 audio_service 与 just_audio 一起使用,并使用我在存储库中找到的教程代码构建了一个最小的示例存储库。
如果我用来初始化 AudioPlayerHandler 的 URL 由于任何原因不正确(在示例代码中硬编码只是为了说明目的,请参阅下面的 link)我无法找到一种方法来检测错误。有一个未处理的异常扰乱了状态,我不知道如何捕获它并在应用程序中采取适当的步骤让用户知道出现了错误。有回电之类的可以听吗?
[VERBOSE-2:ui_dart_state.cc(209)] Unhandled Exception: (-1100) The requested URL was not found on this server.
#0 AudioPlayer._load (package:just_audio/just_audio.dart:785)
<asynchronous suspension>
#1 AudioPlayer._setPlatformActive.setPlatform (package:just_audio/just_audio.dart:1351)
<asynchronous suspension>
这是来自发布的“捕捉玩家错误”部分的片段。dev/packages/just_audio
try {
await player.setUrl("https://s3.amazonaws.com/404-file.mp3");
} on PlayerException catch (e) {
// iOS/macOS: maps to NSError.code
// Android: maps to ExoPlayerException.type
// Web: maps to MediaError.code
// Linux/Windows: maps to PlayerErrorCode.index
print("Error code: ${e.code}");
// iOS/macOS: maps to NSError.localizedDescription
// Android: maps to ExoPlaybackException.getMessage()
// Web/Linux: a generic message
// Windows: MediaPlayerError.message
print("Error message: ${e.message}");
} on PlayerInterruptedException catch (e) {
// This call was interrupted since another audio source was loaded or the
// player was stopped or disposed before this audio source could complete
// loading.
print("Connection aborted: ${e.message}");
} catch (e) {
// Fallback for all errors
print(e);
}
我将 audio_service 与 just_audio 一起使用,并使用我在存储库中找到的教程代码构建了一个最小的示例存储库。
如果我用来初始化 AudioPlayerHandler 的 URL 由于任何原因不正确(在示例代码中硬编码只是为了说明目的,请参阅下面的 link)我无法找到一种方法来检测错误。有一个未处理的异常扰乱了状态,我不知道如何捕获它并在应用程序中采取适当的步骤让用户知道出现了错误。有回电之类的可以听吗?
[VERBOSE-2:ui_dart_state.cc(209)] Unhandled Exception: (-1100) The requested URL was not found on this server.
#0 AudioPlayer._load (package:just_audio/just_audio.dart:785)
<asynchronous suspension>
#1 AudioPlayer._setPlatformActive.setPlatform (package:just_audio/just_audio.dart:1351)
<asynchronous suspension>
这是来自发布的“捕捉玩家错误”部分的片段。dev/packages/just_audio
try {
await player.setUrl("https://s3.amazonaws.com/404-file.mp3");
} on PlayerException catch (e) {
// iOS/macOS: maps to NSError.code
// Android: maps to ExoPlayerException.type
// Web: maps to MediaError.code
// Linux/Windows: maps to PlayerErrorCode.index
print("Error code: ${e.code}");
// iOS/macOS: maps to NSError.localizedDescription
// Android: maps to ExoPlaybackException.getMessage()
// Web/Linux: a generic message
// Windows: MediaPlayerError.message
print("Error message: ${e.message}");
} on PlayerInterruptedException catch (e) {
// This call was interrupted since another audio source was loaded or the
// player was stopped or disposed before this audio source could complete
// loading.
print("Connection aborted: ${e.message}");
} catch (e) {
// Fallback for all errors
print(e);
}