Return null when duration is unknown
This commit is contained in:
parent
c7543941c3
commit
c0f7feeee8
|
@ -89,7 +89,7 @@ class AudioPlayer {
|
||||||
updateTime: Duration.zero,
|
updateTime: Duration.zero,
|
||||||
bufferedPosition: Duration.zero,
|
bufferedPosition: Duration.zero,
|
||||||
speed: 1.0,
|
speed: 1.0,
|
||||||
duration: Duration.zero,
|
duration: null,
|
||||||
icyMetadata: IcyMetadata(
|
icyMetadata: IcyMetadata(
|
||||||
info: IcyInfo(title: null, url: null),
|
info: IcyInfo(title: null, url: null),
|
||||||
headers: IcyHeaders(
|
headers: IcyHeaders(
|
||||||
|
@ -133,8 +133,9 @@ class AudioPlayer {
|
||||||
_eventChannelStream = EventChannel('com.ryanheise.just_audio.events.$_id')
|
_eventChannelStream = EventChannel('com.ryanheise.just_audio.events.$_id')
|
||||||
.receiveBroadcastStream()
|
.receiveBroadcastStream()
|
||||||
.map((data) {
|
.map((data) {
|
||||||
final duration =
|
final duration = data.length < 7 || data[6] < 0
|
||||||
Duration(milliseconds: data.length < 7 || data[6] < 0 ? -1 : data[6]);
|
? null
|
||||||
|
: Duration(milliseconds: data[6]);
|
||||||
_durationFuture = Future.value(duration);
|
_durationFuture = Future.value(duration);
|
||||||
_durationSubject.add(duration);
|
_durationSubject.add(duration);
|
||||||
return _audioPlaybackEvent = AudioPlaybackEvent(
|
return _audioPlaybackEvent = AudioPlaybackEvent(
|
||||||
|
@ -252,6 +253,8 @@ class AudioPlayer {
|
||||||
/// audio, or a [PlatformException] if this call was interrupted by another
|
/// audio, or a [PlatformException] if this call was interrupted by another
|
||||||
/// call to [setUrl], [setFilePath], [setAsset] or [stop].
|
/// call to [setUrl], [setFilePath], [setAsset] or [stop].
|
||||||
///
|
///
|
||||||
|
/// If the duration is unknown, null will be returned.
|
||||||
|
///
|
||||||
/// On platforms except for 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.
|
||||||
|
@ -271,10 +274,8 @@ class AudioPlayer {
|
||||||
}
|
}
|
||||||
url = _proxy.addUrl(url, headers);
|
url = _proxy.addUrl(url, headers);
|
||||||
}
|
}
|
||||||
_durationFuture = _invokeMethod('setUrl', [url]).then((ms) =>
|
_durationFuture = _invokeMethod('setUrl', [url]).then(
|
||||||
(ms == null || ms < 0)
|
(ms) => (ms == null || ms < 0) ? null : Duration(milliseconds: ms));
|
||||||
? const Duration(milliseconds: -1)
|
|
||||||
: Duration(milliseconds: ms));
|
|
||||||
final duration = await _durationFuture;
|
final duration = await _durationFuture;
|
||||||
_durationSubject.add(duration);
|
_durationSubject.add(duration);
|
||||||
return duration;
|
return duration;
|
||||||
|
@ -486,7 +487,7 @@ class AudioPlaybackEvent {
|
||||||
/// The playback speed.
|
/// The playback speed.
|
||||||
final double speed;
|
final double speed;
|
||||||
|
|
||||||
/// The media duration.
|
/// The media duration, or null if unknown.
|
||||||
final Duration duration;
|
final Duration duration;
|
||||||
|
|
||||||
final IcyMetadata icyMetadata;
|
final IcyMetadata icyMetadata;
|
||||||
|
@ -530,7 +531,7 @@ class AudioPlaybackEvent {
|
||||||
(Duration(milliseconds: DateTime.now().millisecondsSinceEpoch) -
|
(Duration(milliseconds: DateTime.now().millisecondsSinceEpoch) -
|
||||||
updateTime) *
|
updateTime) *
|
||||||
speed;
|
speed;
|
||||||
return result <= duration ? result : duration;
|
return duration == null || result <= duration ? result : duration;
|
||||||
} else {
|
} else {
|
||||||
return updatePosition;
|
return updatePosition;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue