Report errors and duration stream on web
This commit is contained in:
parent
f0ad4cdd50
commit
4f383b9393
|
@ -9,16 +9,15 @@ 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 | ✅ | ✅ | ✅ | |
|
||||
| request headers | ✅ | ✅ | ✅ | |
|
||||
| DASH | ✅ | (untested) | (untested) | (untested) |
|
||||
| HLS | ✅ | ✅ | (untested) | (untested) |
|
||||
| play/pause/stop/seek | ✅ | ✅ | ✅ | ✅ |
|
||||
| set volume | ✅ | (untested) | (untested) | (untested) |
|
||||
| set volume | ✅ | (untested) | (untested) | ✅ |
|
||||
| set speed | ✅ | ✅ | ✅ | ✅ |
|
||||
| clip audio | ✅ | | | ✅ |
|
||||
| dispose | ✅ | ✅ | ✅ | ✅ |
|
||||
| report player errors | ✅ | ✅ | ✅ | |
|
||||
| request headers | ✅ | ✅ | ✅ | |
|
||||
| report player errors | ✅ | ✅ | ✅ | ✅ |
|
||||
|
||||
This plugin has been tested on Android and Web, and is being made available for testing on iOS. Please consider reporting any bugs you encounter [here](https://github.com/ryanheise/just_audio/issues) or submitting pull requests [here](https://github.com/ryanheise/just_audio/pulls).
|
||||
|
||||
|
|
|
@ -102,15 +102,27 @@ abstract class JustAudioPlayer {
|
|||
|
||||
double getCurrentPosition();
|
||||
|
||||
int getCurrentPositionMs() => (getCurrentPosition() * 1000).toInt();
|
||||
|
||||
double getDuration();
|
||||
|
||||
int getDurationMs() {
|
||||
final duration = getDuration();
|
||||
return duration.isFinite ? (duration * 1000).toInt() : -1;
|
||||
}
|
||||
|
||||
broadcastPlaybackEvent() {
|
||||
var updateTime = DateTime.now().millisecondsSinceEpoch;
|
||||
eventController.add([
|
||||
_state.index,
|
||||
_buffering,
|
||||
(getCurrentPosition() * 1000).toInt(),
|
||||
getCurrentPositionMs(),
|
||||
updateTime,
|
||||
// TODO: buffered position
|
||||
(getCurrentPosition() * 1000).toInt(),
|
||||
getCurrentPositionMs(),
|
||||
// TODO: Icy Metadata
|
||||
null,
|
||||
getDurationMs(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -131,7 +143,10 @@ class Html5AudioPlayer extends JustAudioPlayer {
|
|||
Html5AudioPlayer({@required String id, @required Registrar registrar})
|
||||
: super(id: id, registrar: registrar) {
|
||||
_audioElement.addEventListener('durationchange', (event) {
|
||||
_durationCompleter?.complete(_audioElement.duration);
|
||||
_durationCompleter?.complete(getDuration());
|
||||
});
|
||||
_audioElement.addEventListener('error', (event) {
|
||||
_durationCompleter?.completeError(_audioElement.error);
|
||||
});
|
||||
_audioElement.addEventListener('ended', (event) {
|
||||
transition(AudioPlaybackState.completed);
|
||||
|
@ -154,9 +169,15 @@ class Html5AudioPlayer extends JustAudioPlayer {
|
|||
_audioElement.src = url;
|
||||
_audioElement.preload = 'auto';
|
||||
_audioElement.load();
|
||||
final duration = await _durationCompleter.future;
|
||||
try {
|
||||
await _durationCompleter.future;
|
||||
} on MediaError catch (e) {
|
||||
throw PlatformException(code: "${e.code}", message: "Failed to load URL");
|
||||
} finally {
|
||||
_durationCompleter = null;
|
||||
}
|
||||
transition(AudioPlaybackState.stopped);
|
||||
return (duration * 1000).toInt();
|
||||
return getDurationMs();
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -229,6 +250,9 @@ class Html5AudioPlayer extends JustAudioPlayer {
|
|||
@override
|
||||
double getCurrentPosition() => _audioElement.currentTime;
|
||||
|
||||
@override
|
||||
double getDuration() => _audioElement.duration;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_interruptPlay();
|
||||
|
|
Loading…
Reference in New Issue