fix stop loop mode
This commit is contained in:
parent
b1829a9d77
commit
8936ffce5b
3 changed files with 19 additions and 2 deletions
|
@ -9,6 +9,7 @@ abstract class AudioPlayerDataSource {
|
|||
Stream<PlaybackEventModel> get playbackEventStream;
|
||||
ValueStream<bool> get playingStream;
|
||||
ValueStream<Duration> get positionStream;
|
||||
ValueStream<Duration?> get durationStream;
|
||||
|
||||
Future<void> play();
|
||||
Future<void> pause();
|
||||
|
|
|
@ -35,6 +35,8 @@ class AudioPlayerDataSourceImpl implements AudioPlayerDataSource {
|
|||
}
|
||||
});
|
||||
|
||||
_audioPlayer.durationStream.listen((event) => _durationSubject.add(event));
|
||||
|
||||
_playbackEventModelStream = Rx.combineLatest2<ja.PlaybackEvent, bool, PlaybackEventModel>(
|
||||
_audioPlayer.playbackEventStream,
|
||||
_audioPlayer.playingStream,
|
||||
|
@ -60,6 +62,7 @@ class AudioPlayerDataSourceImpl implements AudioPlayerDataSource {
|
|||
final BehaviorSubject<PlaybackEventModel> _playbackEventSubject = BehaviorSubject();
|
||||
final BehaviorSubject<bool> _playingSubject = BehaviorSubject();
|
||||
final BehaviorSubject<Duration> _positionSubject = BehaviorSubject();
|
||||
final BehaviorSubject<Duration?> _durationSubject = BehaviorSubject();
|
||||
|
||||
late Stream<PlaybackEventModel> _playbackEventModelStream;
|
||||
|
||||
|
@ -75,6 +78,9 @@ class AudioPlayerDataSourceImpl implements AudioPlayerDataSource {
|
|||
@override
|
||||
ValueStream<bool> get playingStream => _playingSubject.stream;
|
||||
|
||||
@override
|
||||
ValueStream<Duration?> get durationStream => _durationSubject.stream;
|
||||
|
||||
@override
|
||||
Future<void> dispose() async {
|
||||
await _currentIndexSubject.close();
|
||||
|
|
|
@ -38,9 +38,19 @@ class AudioPlayerRepositoryImpl implements AudioPlayerRepository {
|
|||
_updateCurrentSong(queue, currentIndexStream.value);
|
||||
}
|
||||
});
|
||||
_currentSongSubject.listen((song) async {
|
||||
if (loopModeStream.value == LoopMode.stop)
|
||||
positionStream.listen((position) async {
|
||||
final durationMs = _audioPlayerDataSource.durationStream.value?.inMilliseconds;
|
||||
final positionMs = position.inMilliseconds;
|
||||
|
||||
if (
|
||||
loopModeStream.value == LoopMode.stop &&
|
||||
durationMs != null &&
|
||||
positionMs.compareTo(durationMs - 250) > 0 && // less than 250 milliseconds in the song remaining
|
||||
_audioPlayerDataSource.playingStream.value // don't skip to next if we aren't playing
|
||||
) {
|
||||
await pause();
|
||||
await seekToNext();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue