This commit is contained in:
Stonegate 2021-01-01 23:42:59 +08:00
parent 26353bb67b
commit ccdfabeb3f
2 changed files with 24 additions and 10 deletions

View File

@ -269,7 +269,6 @@ class AudioPlayerNotifier extends ChangeNotifier {
await _getAutoPlay(); await _getAutoPlay();
var state = await _playerStateStorage.getPlayerState(); var state = await _playerStateStorage.getPlayerState();
print(state.toString());
if (state[0] != '') { if (state[0] != '') {
_playlist = _playlists.firstWhere((p) => p.id == state[0], _playlist = _playlists.firstWhere((p) => p.id == state[0],
orElse: () => _playlists.first); orElse: () => _playlists.first);
@ -298,12 +297,20 @@ class AudioPlayerNotifier extends ChangeNotifier {
} }
Future<void> playFromLastPosition() async { Future<void> playFromLastPosition() async {
_audioState = AudioProcessingState.none; if (_playlist.episodes.isNotEmpty) {
_playerRunning = true; await _playlist.getPlaylist();
notifyListeners(); if (_episode == null || !_playlist.episodes.contains(_episode))
_startAudioService(_playlist, _episode = _playlist.episodes.first;
position: _lastPostion ?? 0, _audioState = AudioProcessingState.none;
index: _playlist.episodes.indexOf(_episode)); _backgroundAudioDuration = 0;
_backgroundAudioPosition = 0;
_seekSliderValue = 0;
_playerRunning = true;
notifyListeners();
_startAudioService(_playlist,
position: _lastPostion ?? 0,
index: _playlist.episodes.indexOf(_episode));
}
} }
Future<void> playlistLoad(Playlist playlist) async { Future<void> playlistLoad(Playlist playlist) async {
@ -326,7 +333,7 @@ class AudioPlayerNotifier extends ChangeNotifier {
_audioState = AudioProcessingState.none; _audioState = AudioProcessingState.none;
_playerRunning = true; _playerRunning = true;
notifyListeners(); notifyListeners();
_startAudioService(_playlist, position: _lastPostion ?? 0, index: 0); _startAudioService(_playlist, position: 0, index: 0);
} }
} }
} }
@ -683,6 +690,10 @@ class AudioPlayerNotifier extends ChangeNotifier {
for (var p in _playlists) for (var p in _playlists)
if (p != playlist) p if (p != playlist) p
]; ];
if (_playlist == playlist && !_playerRunning) {
_playlist = _queue;
_episode = _queue.episodes.first;
}
notifyListeners(); notifyListeners();
_savePlaylists(); _savePlaylists();
} }
@ -731,7 +742,10 @@ class AudioPlayerNotifier extends ChangeNotifier {
{bool updateEpisodes = true}) async { {bool updateEpisodes = true}) async {
if (updateEpisodes) await playlist.getPlaylist(); if (updateEpisodes) await playlist.getPlaylist();
_playlists = [for (var p in _playlists) p.id == playlist.id ? playlist : p]; _playlists = [for (var p in _playlists) p.id == playlist.id ? playlist : p];
notifyListeners(); if (_playlist.id == playlist.id && !_playerRunning) {
_playlist = _playlists.firstWhere((e) => e.id == _playlist.id);
notifyListeners();
}
_savePlaylists(); _savePlaylists();
} }

View File

@ -264,7 +264,7 @@ class GroupList extends ChangeNotifier {
} }
} }
Future _start() async { Future<void> _start() async {
if (!_created) { if (!_created) {
await _createIsolate(); await _createIsolate();
_created = true; _created = true;