Skip to content

Commit

Permalink
Handle non existing file
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustl22 committed Sep 27, 2023
1 parent 445fb70 commit 58b1f2b
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -122,7 +123,17 @@ class AudioplayersPlugin : FlutterPlugin, IUpdateCallback {
"setSourceUrl" -> {
val url = call.argument<String>("url") ?: error("url is required")
val isLocal = call.argument<Boolean>("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" -> {
Expand Down

0 comments on commit 58b1f2b

Please sign in to comment.