dep upgrades, simplified loadQueue
This commit is contained in:
parent
ff65e42494
commit
f98154e019
5 changed files with 42 additions and 59 deletions
|
@ -21,7 +21,7 @@ class MyAudioHandler extends BaseAudioHandler {
|
|||
});
|
||||
|
||||
_audioPlayer.currentSongStream.listen((songModel) {
|
||||
mediaItemSubject.add(songModel.toMediaItem());
|
||||
mediaItem.add(songModel.toMediaItem());
|
||||
});
|
||||
|
||||
_audioPlayer.playbackEventStream.listen((event) {
|
||||
|
@ -52,7 +52,7 @@ class MyAudioHandler extends BaseAudioHandler {
|
|||
if (_playerStateDataSource.queueStream != null && _playerStateDataSource.currentIndexStream != null) {
|
||||
_audioPlayer.loadQueue(
|
||||
queue: await _playerStateDataSource.queueStream.first,
|
||||
startIndex: await _playerStateDataSource.currentIndexStream.first,
|
||||
initialIndex: await _playerStateDataSource.currentIndexStream.first,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -159,11 +159,11 @@ class MyAudioHandler extends BaseAudioHandler {
|
|||
_audioPlayer.removeQueueIndex(index);
|
||||
}
|
||||
|
||||
void _handleSetQueue(List<QueueItemModel> queue) {
|
||||
_playerStateDataSource.setQueue(queue);
|
||||
void _handleSetQueue(List<QueueItemModel> queueItems) {
|
||||
_playerStateDataSource.setQueue(queueItems);
|
||||
|
||||
final mediaItems = queue.map((e) => e.song.toMediaItem()).toList();
|
||||
queueSubject.add(mediaItems);
|
||||
final mediaItems = queueItems.map((e) => e.song.toMediaItem()).toList();
|
||||
queue.add(mediaItems);
|
||||
}
|
||||
|
||||
void _handlePlaybackEvent(PlaybackEventModel pe) {
|
||||
|
@ -174,14 +174,14 @@ class MyAudioHandler extends BaseAudioHandler {
|
|||
|
||||
if (pe.processingState == ProcessingState.ready) {
|
||||
if (_audioPlayer.playingStream.value) {
|
||||
playbackStateSubject.add(playbackState.value.copyWith(
|
||||
playbackState.add(playbackState.value.copyWith(
|
||||
controls: [MediaControl.skipToPrevious, MediaControl.pause, MediaControl.skipToNext],
|
||||
playing: true,
|
||||
processingState: AudioProcessingState.ready,
|
||||
updatePosition: pe.updatePosition,
|
||||
));
|
||||
} else {
|
||||
playbackStateSubject.add(playbackState.value.copyWith(
|
||||
playbackState.add(playbackState.value.copyWith(
|
||||
controls: [MediaControl.skipToPrevious, MediaControl.play, MediaControl.skipToNext],
|
||||
processingState: AudioProcessingState.ready,
|
||||
updatePosition: pe.updatePosition,
|
||||
|
|
|
@ -23,7 +23,7 @@ abstract class AudioPlayer {
|
|||
Future<void> seekToPrevious();
|
||||
Future<void> dispose();
|
||||
|
||||
Future<void> loadQueue({List<QueueItemModel> queue, int startIndex});
|
||||
Future<void> loadQueue({List<QueueItemModel> queue, int initialIndex});
|
||||
Future<void> addToQueue(SongModel song);
|
||||
Future<void> moveQueueItem(int oldIndex, int newIndex);
|
||||
Future<void> removeQueueIndex(int index);
|
||||
|
|
|
@ -14,7 +14,6 @@ import 'queue_generator.dart';
|
|||
class AudioPlayerImpl implements AudioPlayer {
|
||||
AudioPlayerImpl(this._audioPlayer, this._queueGenerator) {
|
||||
_audioPlayer.currentIndexStream.listen((event) {
|
||||
print('currentIndex: $event');
|
||||
_currentIndexSubject.add(event);
|
||||
if (_queueSubject.value != null) {
|
||||
_currentSongSubject.add(_queueSubject.value[event].song);
|
||||
|
@ -95,26 +94,18 @@ class AudioPlayerImpl implements AudioPlayer {
|
|||
}
|
||||
|
||||
@override
|
||||
Future<void> loadQueue({List<QueueItemModel> queue, int startIndex = 0}) async {
|
||||
if (queue == null || queue.isEmpty ) {
|
||||
Future<void> loadQueue({List<QueueItemModel> queue, int initialIndex = 0}) async {
|
||||
// Not adding to the queue subject as this is meant to load an initial state from the persistent state data source.
|
||||
// This means that the UI already knows the queue.
|
||||
if (queue == null || initialIndex >= queue.length) {
|
||||
return;
|
||||
}
|
||||
if (startIndex >= queue.length) {
|
||||
print('$startIndex >= ${queue.length}');
|
||||
return;
|
||||
}
|
||||
_audioSource = _queueGenerator.songModelsToAudioSource([queue[startIndex].song]);
|
||||
await _audioPlayer.setAudioSource(_audioSource);
|
||||
// await _audioPlayer.load();
|
||||
|
||||
// final smallQueue = queue.sublist(max(initialIndex - 10, 0), min(initialIndex + 140, queue.length));
|
||||
|
||||
final songModelQueue = queue.map((e) => e.song).toList();
|
||||
_queueSubject.add(queue);
|
||||
|
||||
final completeAudioSource = _queueGenerator.songModelsToAudioSource(songModelQueue);
|
||||
_audioSource.insertAll(0, completeAudioSource.children.sublist(0, startIndex));
|
||||
_audioSource.addAll(
|
||||
completeAudioSource.children.sublist(startIndex + 1, completeAudioSource.length),
|
||||
);
|
||||
_audioSource = _queueGenerator.songModelsToAudioSource(songModelQueue);
|
||||
_audioPlayer.setAudioSource(_audioSource, initialIndex: initialIndex);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -124,7 +115,7 @@ class AudioPlayerImpl implements AudioPlayer {
|
|||
|
||||
@override
|
||||
Future<void> play() async {
|
||||
await _audioPlayer.play();
|
||||
_audioPlayer.play();
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -214,7 +205,8 @@ class AudioPlayerImpl implements AudioPlayer {
|
|||
await _audioPlayer.setLoopMode(loopMode.toJA());
|
||||
}
|
||||
|
||||
Future<void> _updateQueue(ja.ConcatenatingAudioSource newQueue, QueueItem currentQueueItem) async {
|
||||
Future<void> _updateQueue(
|
||||
ja.ConcatenatingAudioSource newQueue, QueueItem currentQueueItem) async {
|
||||
final int index = currentQueueItem.originalIndex;
|
||||
|
||||
_audioSource.removeRange(0, _currentIndexSubject.value);
|
||||
|
|
41
pubspec.lock
41
pubspec.lock
|
@ -41,7 +41,7 @@ packages:
|
|||
description:
|
||||
path: "."
|
||||
ref: one-isolate
|
||||
resolved-ref: "88559958955f17c54097f34b9a6365a23eac4899"
|
||||
resolved-ref: d647578d5264ff465fd7bd686b7caa2b9e7373df
|
||||
url: "https://github.com/ryanheise/audio_service.git"
|
||||
source: git
|
||||
version: "0.15.3"
|
||||
|
@ -65,14 +65,14 @@ packages:
|
|||
name: build
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.5.2"
|
||||
version: "1.6.0"
|
||||
build_config:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: build_config
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.4.2"
|
||||
version: "0.4.5"
|
||||
build_daemon:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -86,7 +86,7 @@ packages:
|
|||
name: build_resolvers
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.4.4"
|
||||
version: "1.5.1"
|
||||
build_runner:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
|
@ -100,7 +100,7 @@ packages:
|
|||
name: build_runner_core
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "6.0.3"
|
||||
version: "6.1.5"
|
||||
built_collection:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -135,7 +135,7 @@ packages:
|
|||
name: checked_yaml
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.2"
|
||||
version: "1.0.4"
|
||||
cli_util:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -260,13 +260,6 @@ packages:
|
|||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.4.2"
|
||||
flutter_isolate:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: flutter_isolate
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.0+14"
|
||||
flutter_mobx:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
@ -297,7 +290,7 @@ packages:
|
|||
name: get_it
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "4.0.4"
|
||||
version: "5.0.3"
|
||||
glob:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -364,12 +357,10 @@ packages:
|
|||
just_audio:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
path: just_audio
|
||||
ref: HEAD
|
||||
resolved-ref: "62c369527f749ff06428c8de26d318e77e803cdf"
|
||||
url: "https://github.com/ryanheise/just_audio.git"
|
||||
source: git
|
||||
version: "0.6.1"
|
||||
name: just_audio
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.6.2"
|
||||
just_audio_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -383,7 +374,7 @@ packages:
|
|||
name: just_audio_web
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.2.0"
|
||||
version: "0.2.1"
|
||||
logging:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
@ -572,7 +563,7 @@ packages:
|
|||
name: pubspec_parse
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.1.5"
|
||||
version: "0.1.7"
|
||||
quiver:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -619,7 +610,7 @@ packages:
|
|||
name: source_gen
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.9.7+1"
|
||||
version: "0.9.10+1"
|
||||
source_span:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -654,7 +645,7 @@ packages:
|
|||
name: sqlite3_flutter_libs
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.2.0"
|
||||
version: "0.3.0"
|
||||
sqlparser:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -717,7 +708,7 @@ packages:
|
|||
name: timing
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.1.1+2"
|
||||
version: "0.1.1+3"
|
||||
typed_data:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
12
pubspec.yaml
12
pubspec.yaml
|
@ -20,11 +20,11 @@ dependencies:
|
|||
sdk: flutter
|
||||
flutter_audio_query: ^0.3.5
|
||||
flutter_mobx: ^1.1.0
|
||||
get_it: ^4.0.2
|
||||
just_audio: # ^0.6.1
|
||||
git:
|
||||
url: https://github.com/ryanheise/just_audio.git
|
||||
path: just_audio
|
||||
get_it: ^5.0.0
|
||||
just_audio: ^0.6.2
|
||||
# git:
|
||||
# url: https://github.com/ryanheise/just_audio.git
|
||||
# path: just_audio
|
||||
logging: ^0.11.4
|
||||
mobx: ^1.1.1
|
||||
moor: ^3.0.2
|
||||
|
@ -32,7 +32,7 @@ dependencies:
|
|||
path:
|
||||
path_provider: ^1.6.18
|
||||
provider: ^4.0.4
|
||||
sqlite3_flutter_libs: ^0.2.0
|
||||
sqlite3_flutter_libs: ^0.3.0
|
||||
|
||||
dev_dependencies:
|
||||
build_runner: 1.10.11
|
||||
|
|
Loading…
Add table
Reference in a new issue