From 9614ec6e98cccbf421e81d33815650f1ffa52ef0 Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Mon, 21 Feb 2022 20:55:42 -0800 Subject: [PATCH] Add option to quit on natural stop When the option is enabled, and playback comes to a completion, the player will quit on its own. Signed-off-by: Christopher Snowhill --- Application/AppController.m | 2 ++ Application/PlaybackController.m | 8 +++++- Audio/AudioPlayer.h | 1 + Audio/AudioPlayer.m | 6 +++++ .../Preferences/Base.lproj/Preferences.xib | 27 +++++++++++++------ 5 files changed, 35 insertions(+), 9 deletions(-) diff --git a/Application/AppController.m b/Application/AppController.m index 5e8277632..10cc5ecd4 100644 --- a/Application/AppController.m +++ b/Application/AppController.m @@ -458,6 +458,8 @@ void *kAppControllerContext = &kAppControllerContext; [userDefaultsValuesDict setObject:[NSNumber numberWithBool:NO] forKey:@"resumePlaybackOnStartup"]; + [userDefaultsValuesDict setObject:[NSNumber numberWithBool:NO] forKey:@"quitOnNaturalStop"]; + // Register and sync defaults [[NSUserDefaults standardUserDefaults] registerDefaults:userDefaultsValuesDict]; [[NSUserDefaults standardUserDefaults] synchronize]; diff --git a/Application/PlaybackController.m b/Application/PlaybackController.m index e128078f0..7f5f8d33b 100644 --- a/Application/PlaybackController.m +++ b/Application/PlaybackController.m @@ -626,7 +626,7 @@ NSDictionary *makeRGInfo(PlaylistEntry *pe) { break; default: - DLog(@"STOPED!"); + DLog(@"STOPPED!"); break; } @@ -643,6 +643,12 @@ NSDictionary *makeRGInfo(PlaylistEntry *pe) { [self sendMetaData]; } +- (void)audioPlayer:(AudioPlayer *)player didStopNaturally:(id)userInfo { + if([[NSUserDefaults standardUserDefaults] boolForKey:@"quitOnNaturalStop"]) { + [NSApp terminate:nil]; + } +} + - (void)audioPlayer:(AudioPlayer *)player sustainHDCD:(id)userInfo { MainWindow *mainWindow = (MainWindow *)appController.mainWindow; [mainWindow showHDCDLogo:YES]; diff --git a/Audio/AudioPlayer.h b/Audio/AudioPlayer.h index 609aca9f8..c7ba35f2d 100644 --- a/Audio/AudioPlayer.h +++ b/Audio/AudioPlayer.h @@ -121,6 +121,7 @@ - (void)audioPlayer:(AudioPlayer *)player willEndStream:(id)userInfo; // You must use setNextStream in this method - (void)audioPlayer:(AudioPlayer *)player didBeginStream:(id)userInfo; - (void)audioPlayer:(AudioPlayer *)player didChangeStatus:(id)status userInfo:(id)userInfo; +- (void)audioPlayer:(AudioPlayer *)player didStopNaturally:(id)userInfo; - (void)audioPlayer:(AudioPlayer *)player displayEqualizer:(AudioUnit)eq; - (void)audioPlayer:(AudioPlayer *)player refreshEqualizer:(AudioUnit)eq; - (void)audioPlayer:(AudioPlayer *)player removeEqualizer:(AudioUnit)eq; diff --git a/Audio/AudioPlayer.m b/Audio/AudioPlayer.m index 77738de42..21253b581 100644 --- a/Audio/AudioPlayer.m +++ b/Audio/AudioPlayer.m @@ -259,6 +259,10 @@ [self sendDelegateMethod:@selector(audioPlayer:didBeginStream:) withObject:userInfo waitUntilDone:YES]; } +- (void)notifyPlaybackStopped:(id)userInfo { + [self sendDelegateMethod:@selector(audioPlayer:didStopNaturally:) withObject:userInfo waitUntilDone:NO]; +} + - (void)beginEqualizer:(AudioUnit)eq { [self sendDelegateMethod:@selector(audioPlayer:displayEqualizer:) withVoid:eq waitUntilDone:YES]; } @@ -425,6 +429,8 @@ bufferChain = nil; + [self notifyPlaybackStopped:nil]; + return; } diff --git a/Preferences/Preferences/Base.lproj/Preferences.xib b/Preferences/Preferences/Base.lproj/Preferences.xib index 657391cd9..3dc67ab9a 100644 --- a/Preferences/Preferences/Base.lproj/Preferences.xib +++ b/Preferences/Preferences/Base.lproj/Preferences.xib @@ -22,11 +22,11 @@ - + - + @@ -46,7 +46,7 @@ - + @@ -55,7 +55,7 @@ - + @@ -76,7 +76,7 @@ - + @@ -97,7 +97,7 @@ + - +