Update audio state controller

This commit is contained in:
stonega 2021-10-06 18:47:09 +08:00
parent 8a128dc6ad
commit ad7541d2fc
3 changed files with 15 additions and 13 deletions

View File

@ -42,6 +42,7 @@ android {
lintOptions {
disable 'InvalidPackage'
checkReleaseBuilds false
}
defaultConfig {

View File

@ -203,7 +203,7 @@ class AudioPlayerNotifier extends ChangeNotifier {
AudioServiceConfig get _config => AudioServiceConfig(
androidNotificationChannelName: 'Tsacdop',
androidNotificationIcon: 'drawable/ic_notification',
androidEnableQueue: true,
// androidEnableQueue: true,
androidStopForegroundOnPause: true,
preloadArtwork: false,
fastForwardInterval: Duration(seconds: _fastForwardSeconds),
@ -357,6 +357,8 @@ class AudioPlayerNotifier extends ChangeNotifier {
_startAudioService(_playlist,
position: _lastPosition ?? 0,
index: _playlist.episodes.indexOf(_episode));
} else {
log('Playlist is empty');
}
}
@ -598,7 +600,11 @@ class AudioPlayerNotifier extends ChangeNotifier {
_lastPosition ~/ 1000, _seekSliderValue);
await _dbHelper.saveHistory(history);
}
//_episode = null;
if (_playlist.isEmpty) {
_episode = null;
_backgroundAudioDuration = 0;
_backgroundAudioPosition = 0;
}
}
if (event is Map && event['position'] != null) {
_backgroundAudioPosition = event['position'].inMilliseconds;
@ -1126,14 +1132,14 @@ class CustomAudioHandler extends BaseAudioHandler
@override
Future<void> skipToNext() async {
if (queue.value.length == 0 || _stopAtEnd) {
if (queue.value.length == 1 || _stopAtEnd) {
await Future.delayed(Duration(milliseconds: 200));
await stop();
} else {
_autoSkip = false;
await super.skipToNext();
_player.seekToNext();
if (_isQueue && queue.value.isNotEmpty) {
if (_isQueue) {
removeQueueItemAt(0);
}
}
@ -1141,7 +1147,7 @@ class CustomAudioHandler extends BaseAudioHandler
@override
Future<void> play() async {
if (playing == null) {
if (playing == null || playing == false) {
log('playing');
await super.play();
await _player.play();
@ -1209,9 +1215,8 @@ class CustomAudioHandler extends BaseAudioHandler
Future<void> stop() async {
await _player.stop();
await _player.dispose();
playbackState.add(playbackState.value
.copyWith(processingState: AudioProcessingState.loading));
// await _player.dispose();
_playlist.clear();
customEvent.add({'playerRunning': false});
await super.stop();
}

View File

@ -51,16 +51,12 @@ dependencies:
workmanager: ^0.2.3
wc_flutter_share: ^0.4.0
xml: ^5.2.0
audio_service: 0.18.0
just_audio:
git:
url: https://github.com/stonega/just_audio_origin.git
ref: update
path: just_audio
audio_service:
git:
url: https://github.com/ryanheise/audio_service.git
ref: one-isolate
path: audio_service
flutter_downloader:
git:
url: https://github.com/stonega/flutter_downloader.git