From ad7541d2fc455e774d39c0e237ef13fd9a5f7a9a Mon Sep 17 00:00:00 2001 From: stonega Date: Wed, 6 Oct 2021 18:47:09 +0800 Subject: [PATCH] Update audio state controller --- android/app/build.gradle | 1 + lib/state/audio_state.dart | 21 +++++++++++++-------- pubspec.yaml | 6 +----- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index f4e182a..4fa572b 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -42,6 +42,7 @@ android { lintOptions { disable 'InvalidPackage' + checkReleaseBuilds false } defaultConfig { diff --git a/lib/state/audio_state.dart b/lib/state/audio_state.dart index b89e70f..7ccffef 100644 --- a/lib/state/audio_state.dart +++ b/lib/state/audio_state.dart @@ -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 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 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 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(); } diff --git a/pubspec.yaml b/pubspec.yaml index 86a1fd6..3ace3b5 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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