fix queue update after resume
This commit is contained in:
parent
f8a7136472
commit
b30f07588d
5 changed files with 24 additions and 0 deletions
|
@ -1,6 +1,8 @@
|
|||
import 'package:audio_service/audio_service.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../system/datasources/audio_player_task.dart';
|
||||
|
||||
class AudioServiceWidget extends StatefulWidget {
|
||||
const AudioServiceWidget({@required this.child});
|
||||
|
||||
|
@ -31,9 +33,12 @@ class _AudioServiceWidgetState extends State<AudioServiceWidget>
|
|||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
switch (state) {
|
||||
case AppLifecycleState.resumed:
|
||||
print('AppLifecycleState.resumed');
|
||||
AudioService.connect();
|
||||
AudioService.customAction(APP_LIFECYCLE_RESUMED);
|
||||
break;
|
||||
case AppLifecycleState.paused:
|
||||
print('AppLifecycleState.paused');
|
||||
AudioService.disconnect();
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -10,6 +10,7 @@ import 'moor_music_data_source.dart';
|
|||
|
||||
const String INIT = 'INIT';
|
||||
const String PLAY_WITH_CONTEXT = 'PLAY_WITH_CONTEXT';
|
||||
const String APP_LIFECYCLE_RESUMED = 'APP_LIFECYCLE_RESUMED';
|
||||
|
||||
const String KEY_INDEX = 'INDEX';
|
||||
|
||||
|
@ -112,6 +113,8 @@ class AudioPlayerTask extends BackgroundAudioTask {
|
|||
final _context = List<String>.from(args[0] as List<dynamic>);
|
||||
final index = args[1] as int;
|
||||
return _playWithContext(_context, index);
|
||||
case APP_LIFECYCLE_RESUMED:
|
||||
return _onAppLifecycleResumed();
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
@ -136,6 +139,11 @@ class AudioPlayerTask extends BackgroundAudioTask {
|
|||
_startPlayback(index);
|
||||
}
|
||||
|
||||
Future<void> _onAppLifecycleResumed() async {
|
||||
playbackIndex = playbackIndex;
|
||||
// AudioServiceBackground.setQueue(_playbackContext);
|
||||
}
|
||||
|
||||
// TODO: test
|
||||
// TODO: optimize -> too slow for whole library
|
||||
Future<List<MediaItem>> _getMediaItemsFromPaths(List<String> paths) async {
|
||||
|
|
|
@ -16,6 +16,7 @@ class LocalMusicFetcherImpl implements LocalMusicFetcher {
|
|||
await flutterAudioQuery.getArtists();
|
||||
return artistInfoList
|
||||
.map((ArtistInfo artistInfo) => ArtistModel.fromArtistInfo(artistInfo))
|
||||
.toSet()
|
||||
.toList();
|
||||
}
|
||||
|
||||
|
|
|
@ -41,6 +41,11 @@ class AlbumModel extends Album {
|
|||
|
||||
final int id;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return '$title';
|
||||
}
|
||||
|
||||
AlbumsCompanion toAlbumsCompanion() => AlbumsCompanion(
|
||||
title: Value(title),
|
||||
artist: Value(artist),
|
||||
|
|
|
@ -22,6 +22,11 @@ class ArtistModel extends Artist {
|
|||
);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
ArtistsCompanion toArtistsCompanion() => ArtistsCompanion(
|
||||
name: Value(name),
|
||||
);
|
||||
|
|
Loading…
Add table
Reference in a new issue