fixed state transitions for just_audio 0.6.3
This commit is contained in:
parent
f4adfbe42c
commit
2cb557ab6f
5 changed files with 25 additions and 30 deletions
|
@ -1,14 +1,14 @@
|
|||
class PlaybackEvent {
|
||||
PlaybackEvent({
|
||||
this.duration,
|
||||
this.index,
|
||||
this.playing,
|
||||
this.processingState,
|
||||
this.updatePosition,
|
||||
this.updateTime,
|
||||
});
|
||||
|
||||
final Duration duration;
|
||||
final int index;
|
||||
final bool playing;
|
||||
final ProcessingState processingState;
|
||||
final Duration updatePosition;
|
||||
final DateTime updateTime;
|
||||
|
|
|
@ -9,7 +9,7 @@ import '../models/song_model.dart';
|
|||
abstract class AudioPlayer {
|
||||
ValueStream<int> get currentIndexStream;
|
||||
ValueStream<SongModel> get currentSongStream;
|
||||
ValueStream<PlaybackEventModel> get playbackEventStream;
|
||||
Stream<PlaybackEventModel> get playbackEventStream;
|
||||
ValueStream<bool> get playingStream;
|
||||
ValueStream<Duration> get positionStream;
|
||||
ValueStream<List<QueueItemModel>> get queueStream;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import 'package:just_audio/just_audio.dart' as ja;
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:rxdart/rxdart.dart';
|
||||
|
||||
import '../../domain/entities/loop_mode.dart';
|
||||
|
@ -14,16 +15,16 @@ import 'queue_generator.dart';
|
|||
class AudioPlayerImpl implements AudioPlayer {
|
||||
AudioPlayerImpl(this._audioPlayer, this._queueGenerator) {
|
||||
_audioPlayer.currentIndexStream.listen((event) {
|
||||
_log.info('currentIndex: $event');
|
||||
_currentIndexSubject.add(event);
|
||||
if (_queueSubject.value != null) {
|
||||
_currentSongSubject.add(_queueSubject.value[event].song);
|
||||
}
|
||||
});
|
||||
|
||||
_audioPlayer.playingStream.listen((event) => _playingSubject.add(event));
|
||||
|
||||
_audioPlayer.playbackEventStream.listen((event) {
|
||||
_playbackEventSubject.add(PlaybackEventModel.fromJAPlaybackEvent(event));
|
||||
_audioPlayer.playingStream.listen((event) {
|
||||
_log.info('playing: $event');
|
||||
_playingSubject.add(event);
|
||||
});
|
||||
|
||||
_audioPlayer.positionStream.listen((event) {
|
||||
|
@ -31,6 +32,7 @@ class AudioPlayerImpl implements AudioPlayer {
|
|||
});
|
||||
|
||||
_audioPlayer.loopModeStream.listen((event) {
|
||||
_log.info('loopMode: $event');
|
||||
_loopModeSubject.add(event.toEntity());
|
||||
});
|
||||
|
||||
|
@ -39,6 +41,12 @@ class AudioPlayerImpl implements AudioPlayer {
|
|||
_currentSongSubject.add(event[_currentIndexSubject.value].song);
|
||||
}
|
||||
});
|
||||
|
||||
_playbackEventModelStream = Rx.combineLatest2<ja.PlaybackEvent, bool, PlaybackEventModel>(
|
||||
_audioPlayer.playbackEventStream,
|
||||
_audioPlayer.playingStream,
|
||||
(a, b) => PlaybackEventModel.fromJAPlaybackEvent(a, b),
|
||||
).distinct();
|
||||
}
|
||||
|
||||
final ja.AudioPlayer _audioPlayer;
|
||||
|
@ -48,6 +56,8 @@ class AudioPlayerImpl implements AudioPlayer {
|
|||
List<SongModel> _inputQueue;
|
||||
List<QueueItemModel> _queue;
|
||||
|
||||
static final _log = Logger('AudioPlayer');
|
||||
|
||||
final BehaviorSubject<int> _currentIndexSubject = BehaviorSubject();
|
||||
final BehaviorSubject<SongModel> _currentSongSubject = BehaviorSubject();
|
||||
final BehaviorSubject<PlaybackEventModel> _playbackEventSubject = BehaviorSubject();
|
||||
|
@ -57,6 +67,8 @@ class AudioPlayerImpl implements AudioPlayer {
|
|||
final BehaviorSubject<ShuffleMode> _shuffleModeSubject = BehaviorSubject.seeded(ShuffleMode.none);
|
||||
final BehaviorSubject<LoopMode> _loopModeSubject = BehaviorSubject();
|
||||
|
||||
Stream<PlaybackEventModel> _playbackEventModelStream;
|
||||
|
||||
@override
|
||||
ValueStream<int> get currentIndexStream => _currentIndexSubject.stream;
|
||||
|
||||
|
@ -64,7 +76,7 @@ class AudioPlayerImpl implements AudioPlayer {
|
|||
ValueStream<SongModel> get currentSongStream => _currentSongSubject.stream;
|
||||
|
||||
@override
|
||||
ValueStream<PlaybackEventModel> get playbackEventStream => _playbackEventSubject.stream;
|
||||
Stream<PlaybackEventModel> get playbackEventStream => _playbackEventModelStream;
|
||||
|
||||
@override
|
||||
ValueStream<Duration> get positionStream => _positionSubject.stream;
|
||||
|
|
|
@ -4,46 +4,29 @@ import '../../domain/entities/playback_event.dart';
|
|||
|
||||
class PlaybackEventModel extends PlaybackEvent {
|
||||
PlaybackEventModel({
|
||||
Duration duration,
|
||||
int index,
|
||||
bool playing,
|
||||
ProcessingState processingState,
|
||||
Duration updatePosition,
|
||||
DateTime updateTime,
|
||||
}) : super(
|
||||
duration: duration,
|
||||
index: index,
|
||||
playing: playing,
|
||||
processingState: processingState,
|
||||
updatePosition: updatePosition,
|
||||
updateTime: updateTime,
|
||||
);
|
||||
|
||||
factory PlaybackEventModel.fromJAPlaybackEvent(ja.PlaybackEvent playbackEvent) =>
|
||||
factory PlaybackEventModel.fromJAPlaybackEvent(ja.PlaybackEvent playbackEvent, bool playing) =>
|
||||
PlaybackEventModel(
|
||||
duration: playbackEvent.duration,
|
||||
index: playbackEvent.currentIndex,
|
||||
playing: playing,
|
||||
processingState: playbackEvent.processingState.toProcessingState(),
|
||||
updatePosition: playbackEvent.updatePosition,
|
||||
updateTime: playbackEvent.updateTime,
|
||||
);
|
||||
}
|
||||
|
||||
// extension JAProcessingStateExt on ProcessingState {
|
||||
// ProcessingState fromJAProcessingState(ja.ProcessingState processingState) {
|
||||
// switch (processingState) {
|
||||
// case ja.ProcessingState.loading:
|
||||
// return ProcessingState.loading;
|
||||
// case ja.ProcessingState.buffering:
|
||||
// return ProcessingState.buffering;
|
||||
// case ja.ProcessingState.ready:
|
||||
// return ProcessingState.ready;
|
||||
// case ja.ProcessingState.completed:
|
||||
// return ProcessingState.completed;
|
||||
// default:
|
||||
// return ProcessingState.none;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
extension ProcessingStateExt on ja.ProcessingState {
|
||||
ProcessingState toProcessingState() {
|
||||
switch (this) {
|
||||
|
|
|
@ -22,7 +22,7 @@ dependencies:
|
|||
flutter_audio_query: ^0.3.5
|
||||
flutter_mobx: ^1.1.0
|
||||
get_it: ^5.0.0
|
||||
just_audio: ^0.6.2
|
||||
just_audio: 0.6.3
|
||||
# git:
|
||||
# url: https://github.com/ryanheise/just_audio.git
|
||||
# path: just_audio
|
||||
|
|
Loading…
Add table
Reference in a new issue