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 { lintOptions {
disable 'InvalidPackage' disable 'InvalidPackage'
checkReleaseBuilds false
} }
defaultConfig { defaultConfig {

View File

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

View File

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