diff --git a/packages/audioplayers_android/android/src/main/kotlin/xyz/luan/audioplayers/AudioplayersPlugin.kt b/packages/audioplayers_android/android/src/main/kotlin/xyz/luan/audioplayers/AudioplayersPlugin.kt index 07bf45a94..b220aed15 100644 --- a/packages/audioplayers_android/android/src/main/kotlin/xyz/luan/audioplayers/AudioplayersPlugin.kt +++ b/packages/audioplayers_android/android/src/main/kotlin/xyz/luan/audioplayers/AudioplayersPlugin.kt @@ -19,6 +19,7 @@ import xyz.luan.audioplayers.player.SoundPoolManager import xyz.luan.audioplayers.player.WrappedPlayer import xyz.luan.audioplayers.source.BytesSource import xyz.luan.audioplayers.source.UrlSource +import java.io.FileNotFoundException import java.lang.ref.WeakReference import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.ConcurrentMap @@ -122,7 +123,17 @@ class AudioplayersPlugin : FlutterPlugin, IUpdateCallback { "setSourceUrl" -> { val url = call.argument("url") ?: error("url is required") val isLocal = call.argument("isLocal") ?: false - player.source = UrlSource(url, isLocal) + try { + player.source = UrlSource(url, isLocal) + } catch (e: FileNotFoundException) { + response.error( + "AndroidAudioError", + "Failed to set source. For troubleshooting, see: " + + "https://github.com/bluefireteam/audioplayers/blob/main/troubleshooting.md", + e, + ) + return + } } "setSourceBytes" -> {