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 file | ✅ | ✅ | ✅ | |
| read from asset | ✅ | ✅ | ✅ | |
| pass headers | ✅ | ✅ | ✅ | |
| DASH | ✅ | (untested) | (untested) | (untested) |
| HLS | ✅ | ✅ | (untested) | (untested) |
| play/pause/stop/seek | ✅ | ✅ | ✅ | ✅ |

View File

@ -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 {

View File

@ -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.
///