From 1390d8645520be064f389c70ad138b5ed0c0d6fb Mon Sep 17 00:00:00 2001 From: MSOB7YY Date: Sun, 3 Dec 2023 04:16:31 +0200 Subject: [PATCH] chore: persist audio-only playback for youtube --- lib/controller/audio_handler.dart | 7 +++---- lib/controller/settings_controller.dart | 7 +++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/controller/audio_handler.dart b/lib/controller/audio_handler.dart index a6e060af..418e3100 100644 --- a/lib/controller/audio_handler.dart +++ b/lib/controller/audio_handler.dart @@ -80,8 +80,7 @@ class NamidaAudioVideoHandler extends BasicAudioHandler { bool get isFetchingInfo => _isFetchingInfo.value; final _isFetchingInfo = false.obs; - bool get isAudioOnlyPlayback => _isAudioOnlyPlayback; - bool _isAudioOnlyPlayback = false; + bool get isAudioOnlyPlayback => settings.ytIsAudioOnlyMode.value; bool get isCurrentAudioFromCache => _isCurrentAudioFromCache; bool _isCurrentAudioFromCache = false; @@ -92,8 +91,8 @@ class NamidaAudioVideoHandler extends BasicAudioHandler { // Completer? _audioShouldBeLoading; Future setAudioOnlyPlayback(bool audioOnly) async { - _isAudioOnlyPlayback = audioOnly; - if (_isAudioOnlyPlayback) { + settings.save(ytIsAudioOnlyMode: audioOnly); + if (audioOnly) { currentVideoStream.value = null; currentAudioStream.value = null; currentCachedVideo.value = null; diff --git a/lib/controller/settings_controller.dart b/lib/controller/settings_controller.dart index 7106bbd0..831bd0fd 100644 --- a/lib/controller/settings_controller.dart +++ b/lib/controller/settings_controller.dart @@ -167,6 +167,7 @@ class SettingsController { final RxBool swipeableDrawer = true.obs; final RxBool dismissibleMiniplayer = false.obs; final RxBool enableClipboardMonitoring = false.obs; + final RxBool ytIsAudioOnlyMode = false.obs; final RxList tagFieldsToEdit = [ TagField.trackNumber, TagField.year, @@ -438,6 +439,7 @@ class SettingsController { swipeableDrawer.value = json['swipeableDrawer'] ?? swipeableDrawer.value; dismissibleMiniplayer.value = json['dismissibleMiniplayer'] ?? dismissibleMiniplayer.value; enableClipboardMonitoring.value = json['enableClipboardMonitoring'] ?? enableClipboardMonitoring.value; + ytIsAudioOnlyMode.value = json['ytIsAudioOnlyMode'] ?? ytIsAudioOnlyMode.value; final listFromStorage = List.from(json['tagFieldsToEdit'] ?? []); tagFieldsToEdit.value = listFromStorage.isNotEmpty ? List.from(listFromStorage.map((e) => TagField.values.getEnum(e))) : tagFieldsToEdit; @@ -653,6 +655,7 @@ class SettingsController { 'swipeableDrawer': swipeableDrawer.value, 'dismissibleMiniplayer': dismissibleMiniplayer.value, 'enableClipboardMonitoring': enableClipboardMonitoring.value, + 'ytIsAudioOnlyMode': ytIsAudioOnlyMode.value, 'tagFieldsToEdit': tagFieldsToEdit.mapped((element) => element.convertToString), 'wakelockMode': wakelockMode.value.convertToString, 'localVideoMatchingType': localVideoMatchingType.value.convertToString, @@ -837,6 +840,7 @@ class SettingsController { bool? swipeableDrawer, bool? dismissibleMiniplayer, bool? enableClipboardMonitoring, + bool? ytIsAudioOnlyMode, List? tagFieldsToEdit, WakelockMode? wakelockMode, LocalVideoMatchingType? localVideoMatchingType, @@ -1300,6 +1304,9 @@ class SettingsController { if (enableClipboardMonitoring != null) { this.enableClipboardMonitoring.value = enableClipboardMonitoring; } + if (ytIsAudioOnlyMode != null) { + this.ytIsAudioOnlyMode.value = ytIsAudioOnlyMode; + } if (tagFieldsToEdit != null) { tagFieldsToEdit.loop((d, index) { if (!this.tagFieldsToEdit.contains(d)) {