In setUrl, throw an exception rather than return null if interrupted

This commit is contained in:
Ryan Heise 2020-06-08 21:24:11 +10:00
parent 4dee0906db
commit b13338ef11
3 changed files with 7 additions and 9 deletions

View File

@ -9,6 +9,7 @@ A Flutter plugin to play audio from URLs, files, assets and DASH/HLS streams. Th
| read from URL | ✅ | ✅ | ✅ | ✅ | | read from URL | ✅ | ✅ | ✅ | ✅ |
| read from file | ✅ | ✅ | ✅ | | | read from file | ✅ | ✅ | ✅ | |
| read from asset | ✅ | ✅ | ✅ | | | read from asset | ✅ | ✅ | ✅ | |
| pass headers | ✅ | ✅ | ✅ | |
| DASH | ✅ | (untested) | (untested) | (untested) | | DASH | ✅ | (untested) | (untested) | (untested) |
| HLS | ✅ | ✅ | (untested) | (untested) | | HLS | ✅ | ✅ | (untested) | (untested) |
| play/pause/stop/seek | ✅ | ✅ | ✅ | ✅ | | play/pause/stop/seek | ✅ | ✅ | ✅ | ✅ |

View File

@ -205,7 +205,7 @@ public class AudioPlayer implements MethodCallHandler, Player.EventListener, Met
default: default:
Log.e(TAG, "default: " + error.getUnexpectedException().getMessage()); Log.e(TAG, "default: " + error.getUnexpectedException().getMessage());
} }
this.setError(String.valueOf(error.type), error.getMessage()); sendError(String.valueOf(error.type), error.getMessage());
} }
@Override @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) { if (prepareResult != null) {
prepareResult.error(errorCode, errorMsg, null); prepareResult.error(errorCode, errorMsg, null);
prepareResult = null; prepareResult = null;
@ -515,10 +515,7 @@ public class AudioPlayer implements MethodCallHandler, Player.EventListener, Met
} }
private void abortExistingConnection() { private void abortExistingConnection() {
if (prepareResult != null) { sendError("abort", "Connection aborted");
prepareResult.success(null);
prepareResult = null;
}
} }
enum PlaybackState { enum PlaybackState {

View File

@ -249,10 +249,10 @@ class AudioPlayer {
_automaticallyWaitsToMinimizeStalling; _automaticallyWaitsToMinimizeStalling;
/// Loads audio media from a URL and completes with the duration of that /// 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], /// audio, or a [PlatformException] if this call was interrupted by another
/// [setFilePath] or [setAsset]. /// 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 /// with the request. Currently headers are not recursively applied to items
/// within playlist files such as m3u8. /// within playlist files such as m3u8.
/// ///