From ef8467d9ce2c30ded0a8d6054453db692fa8170d Mon Sep 17 00:00:00 2001 From: Ryan Heise Date: Thu, 2 Jan 2020 00:59:15 +1100 Subject: [PATCH] setUrl completes with null if interrupted --- .../java/com/ryanheise/just_audio/AudioPlayer.java | 2 +- lib/just_audio.dart | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) 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 cf1c961..29f549e 100644 --- a/android/src/main/java/com/ryanheise/just_audio/AudioPlayer.java +++ b/android/src/main/java/com/ryanheise/just_audio/AudioPlayer.java @@ -349,7 +349,7 @@ public class AudioPlayer implements MethodCallHandler, Player.EventListener { private void abortExistingConnection() { if (prepareResult != null) { - prepareResult.error("setUrl aborted", null, null); + prepareResult.success(null); prepareResult = null; } } diff --git a/lib/just_audio.dart b/lib/just_audio.dart index 9894fda..5f2c25d 100644 --- a/lib/just_audio.dart +++ b/lib/just_audio.dart @@ -130,7 +130,9 @@ class AudioPlayer { /// The current speed of the player. double get speed => _speed; - /// Loads audio media from a URL and returns the duration of that audio. + /// 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]. Future setUrl(final String url) async { _durationFuture = _invokeMethod('setUrl', [url]).then((ms) => Duration(milliseconds: ms)); @@ -139,11 +141,15 @@ class AudioPlayer { return duration; } - /// Loads audio media from a file and returns the duration of that audio. + /// Loads audio media from a file and completes with the duration of that + /// audio, or null if this call was interrupted by another call so [setUrl], + /// [setFilePath] or [setAsset]. Future setFilePath(final String filePath) => setUrl('file://$filePath'); - /// Loads audio media from an asset and returns the duration of that audio. + /// Loads audio media from an asset and completes with the duration of that + /// audio, or null if this call was interrupted by another call so [setUrl], + /// [setFilePath] or [setAsset]. Future setAsset(final String assetPath) async { final file = await _cacheFile; if (!file.existsSync()) {