2020-04-07 22:06:43 +02:00
|
|
|
import 'package:meta/meta.dart';
|
|
|
|
import 'package:mobx/mobx.dart';
|
2020-11-15 16:36:50 +01:00
|
|
|
import 'package:mucke/domain/repositories/music_data_repository.dart';
|
2020-04-07 22:06:43 +02:00
|
|
|
|
2020-04-10 20:12:26 +02:00
|
|
|
import '../../domain/entities/playback_state.dart';
|
2020-08-25 16:23:52 +02:00
|
|
|
import '../../domain/entities/shuffle_mode.dart';
|
2020-04-07 22:06:43 +02:00
|
|
|
import '../../domain/entities/song.dart';
|
|
|
|
import '../../domain/repositories/audio_repository.dart';
|
|
|
|
|
|
|
|
part 'audio_store.g.dart';
|
|
|
|
|
|
|
|
class AudioStore extends _AudioStore with _$AudioStore {
|
2020-11-15 16:36:50 +01:00
|
|
|
AudioStore({
|
|
|
|
@required AudioRepository audioRepository,
|
|
|
|
@required MusicDataRepository musicDataRepository,
|
|
|
|
}) : super(audioRepository, musicDataRepository);
|
2020-04-07 22:06:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
abstract class _AudioStore with Store {
|
2020-11-15 16:36:50 +01:00
|
|
|
_AudioStore(this._audioRepository, this._musicDataRepository) {
|
|
|
|
currentSongStream =
|
|
|
|
_audioRepository.currentSongStream.distinct().asObservable();
|
2020-09-19 17:08:48 +02:00
|
|
|
|
|
|
|
currentPositionStream =
|
|
|
|
_audioRepository.currentPositionStream.asObservable(initialValue: 0);
|
|
|
|
|
2020-11-15 16:36:50 +01:00
|
|
|
queueStream =
|
|
|
|
_musicDataRepository.queueStream.asObservable(initialValue: []);
|
2020-09-19 17:08:48 +02:00
|
|
|
|
|
|
|
queueIndexStream = _audioRepository.queueIndexStream.asObservable();
|
|
|
|
|
|
|
|
shuffleModeStream = _audioRepository.shuffleModeStream
|
|
|
|
.asObservable(initialValue: ShuffleMode.none);
|
|
|
|
|
|
|
|
playbackStateStream = _audioRepository.playbackStateStream.asObservable();
|
|
|
|
}
|
2020-04-07 22:06:43 +02:00
|
|
|
|
|
|
|
final AudioRepository _audioRepository;
|
2020-11-15 16:36:50 +01:00
|
|
|
final MusicDataRepository _musicDataRepository;
|
2020-04-07 22:06:43 +02:00
|
|
|
|
2020-04-09 17:50:28 +02:00
|
|
|
@observable
|
2020-09-19 20:30:41 +02:00
|
|
|
ObservableStream<Song> currentSongStream;
|
2020-04-09 17:50:28 +02:00
|
|
|
|
2020-11-15 16:36:50 +01:00
|
|
|
@computed
|
|
|
|
Song get currentSong {
|
|
|
|
print('currentSong!!!');
|
|
|
|
if (queueStream.value != [] && queueIndexStream.status == StreamStatus.active) {
|
|
|
|
final song = queueStream.value[queueIndexStream.value];
|
|
|
|
return song;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-04-10 20:12:26 +02:00
|
|
|
@observable
|
|
|
|
ObservableStream<PlaybackState> playbackStateStream;
|
|
|
|
|
2020-04-11 20:23:02 +02:00
|
|
|
@observable
|
|
|
|
ObservableStream<int> currentPositionStream;
|
|
|
|
|
2020-07-12 18:25:34 +02:00
|
|
|
@observable
|
|
|
|
ObservableStream<List<Song>> queueStream;
|
|
|
|
|
|
|
|
@observable
|
|
|
|
ObservableStream<int> queueIndexStream;
|
|
|
|
|
2020-08-24 16:43:22 +02:00
|
|
|
@observable
|
|
|
|
ObservableStream<ShuffleMode> shuffleModeStream;
|
|
|
|
|
2020-04-07 22:06:43 +02:00
|
|
|
@action
|
|
|
|
Future<void> playSong(int index, List<Song> songList) async {
|
|
|
|
_audioRepository.playSong(index, songList);
|
|
|
|
}
|
|
|
|
|
2020-04-10 20:12:26 +02:00
|
|
|
@action
|
|
|
|
Future<void> play() async {
|
|
|
|
_audioRepository.play();
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
Future<void> pause() async {
|
|
|
|
_audioRepository.pause();
|
|
|
|
}
|
|
|
|
|
2020-07-12 18:25:34 +02:00
|
|
|
@action
|
|
|
|
Future<void> skipToNext() async {
|
|
|
|
_audioRepository.skipToNext();
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
Future<void> skipToPrevious() async {
|
|
|
|
_audioRepository.skipToPrevious();
|
|
|
|
}
|
|
|
|
|
2020-08-24 16:43:22 +02:00
|
|
|
Future<void> setShuffleMode(ShuffleMode shuffleMode) async {
|
|
|
|
_audioRepository.setShuffleMode(shuffleMode);
|
|
|
|
}
|
|
|
|
|
2020-08-25 16:23:52 +02:00
|
|
|
Future<void> shuffleAll() async {
|
|
|
|
_audioRepository.shuffleAll();
|
|
|
|
}
|
2020-10-25 11:54:11 +01:00
|
|
|
|
|
|
|
Future<void> addToQueue(Song song) async {
|
|
|
|
_audioRepository.addToQueue(song);
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> moveQueueItem(int oldIndex, int newIndex) async {
|
|
|
|
_audioRepository.moveQueueItem(oldIndex, newIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> removeQueueItem(int index) async {
|
|
|
|
_audioRepository.removeQueueItem(index);
|
|
|
|
}
|
2020-04-10 20:12:26 +02:00
|
|
|
}
|