From b13338ef115eda7a92ce8dd89c7988f553091509 Mon Sep 17 00:00:00 2001 From: Ryan Heise Date: Mon, 8 Jun 2020 21:24:11 +1000 Subject: [PATCH] In setUrl, throw an exception rather than return null if interrupted --- README.md | 1 + .../main/java/com/ryanheise/just_audio/AudioPlayer.java | 9 +++------ lib/just_audio.dart | 6 +++--- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index f9ba2a1..1dae138 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ A Flutter plugin to play audio from URLs, files, assets and DASH/HLS streams. Th | read from URL | ✅ | ✅ | ✅ | ✅ | | read from file | ✅ | ✅ | ✅ | | | read from asset | ✅ | ✅ | ✅ | | +| pass headers | ✅ | ✅ | ✅ | | | DASH | ✅ | (untested) | (untested) | (untested) | | HLS | ✅ | ✅ | (untested) | (untested) | | play/pause/stop/seek | ✅ | ✅ | ✅ | ✅ | diff --git a/android/src/main/java/com/ryanheise/just_audio/AudioPlayer.java b/android/src/main/java/com/ryanheise/just_audio/AudioPlayer.java index 76dd2c8..05ac4eb 100644 --- a/android/src/main/java/com/ryanheise/just_audio/AudioPlayer.java +++ b/android/src/main/java/com/ryanheise/just_audio/AudioPlayer.java @@ -205,7 +205,7 @@ public class AudioPlayer implements MethodCallHandler, Player.EventListener, Met default: Log.e(TAG, "default: " + error.getUnexpectedException().getMessage()); } - this.setError(String.valueOf(error.type), error.getMessage()); + sendError(String.valueOf(error.type), error.getMessage()); } @Override @@ -353,7 +353,7 @@ public class AudioPlayer implements MethodCallHandler, Player.EventListener, Met } } - private void setError(String errorCode, String errorMsg) { + private void sendError(String errorCode, String errorMsg) { if (prepareResult != null) { prepareResult.error(errorCode, errorMsg, null); prepareResult = null; @@ -515,10 +515,7 @@ public class AudioPlayer implements MethodCallHandler, Player.EventListener, Met } private void abortExistingConnection() { - if (prepareResult != null) { - prepareResult.success(null); - prepareResult = null; - } + sendError("abort", "Connection aborted"); } enum PlaybackState { diff --git a/lib/just_audio.dart b/lib/just_audio.dart index 2adf399..a6b0170 100644 --- a/lib/just_audio.dart +++ b/lib/just_audio.dart @@ -249,10 +249,10 @@ class AudioPlayer { _automaticallyWaitsToMinimizeStalling; /// Loads audio media from a URL and completes with the duration of that - /// audio, or null if this call was interrupted by another call so [setUrl], - /// [setFilePath] or [setAsset]. + /// audio, or a [PlatformException] if this call was interrupted by another + /// call to [setUrl], [setFilePath], [setAsset] or [stop]. /// - /// On platforms other than the web, the supplied [headers] will be passed + /// On platforms except for the web, the supplied [headers] will be passed /// with the request. Currently headers are not recursively applied to items /// within playlist files such as m3u8. ///