Skip to content

Commit

Permalink
chore: persist audio-only playback for youtube
Browse files Browse the repository at this point in the history
  • Loading branch information
MSOB7YY committed Dec 3, 2023
1 parent 17bcf73 commit 1390d86
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/controller/audio_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ class NamidaAudioVideoHandler<Q extends Playable> extends BasicAudioHandler<Q> {
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;
Expand All @@ -92,8 +91,8 @@ class NamidaAudioVideoHandler<Q extends Playable> extends BasicAudioHandler<Q> {
// Completer<void>? _audioShouldBeLoading;

Future<void> setAudioOnlyPlayback(bool audioOnly) async {
_isAudioOnlyPlayback = audioOnly;
if (_isAudioOnlyPlayback) {
settings.save(ytIsAudioOnlyMode: audioOnly);
if (audioOnly) {
currentVideoStream.value = null;
currentAudioStream.value = null;
currentCachedVideo.value = null;
Expand Down
7 changes: 7 additions & 0 deletions lib/controller/settings_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<TagField> tagFieldsToEdit = <TagField>[
TagField.trackNumber,
TagField.year,
Expand Down Expand Up @@ -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<String>.from(json['tagFieldsToEdit'] ?? []);
tagFieldsToEdit.value = listFromStorage.isNotEmpty ? List<TagField>.from(listFromStorage.map((e) => TagField.values.getEnum(e))) : tagFieldsToEdit;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -837,6 +840,7 @@ class SettingsController {
bool? swipeableDrawer,
bool? dismissibleMiniplayer,
bool? enableClipboardMonitoring,
bool? ytIsAudioOnlyMode,
List<TagField>? tagFieldsToEdit,
WakelockMode? wakelockMode,
LocalVideoMatchingType? localVideoMatchingType,
Expand Down Expand Up @@ -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)) {
Expand Down

0 comments on commit 1390d86

Please sign in to comment.