From 3e72087a41facbd609dad33e9962bc1c0319fe5b Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Sun, 9 Jan 2022 02:34:29 -0800 Subject: [PATCH] Play position is stored every 10 seconds, and status is stored every time playback is started, paused, stopped, or seeked --- Application/PlaybackController.h | 1 + Application/PlaybackController.m | 28 ++++++++++++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/Application/PlaybackController.h b/Application/PlaybackController.h index 561936fc0..bde19a7a1 100644 --- a/Application/PlaybackController.h +++ b/Application/PlaybackController.h @@ -37,6 +37,7 @@ extern NSDictionary * makeRGInfo(PlaylistEntry *pe); CogStatus playbackStatus; double position; + double lastPosition; BOOL seekable; BOOL fading; diff --git a/Application/PlaybackController.m b/Application/PlaybackController.m index 05371b185..bed607679 100644 --- a/Application/PlaybackController.m +++ b/Application/PlaybackController.m @@ -99,7 +99,9 @@ NSString *CogPlaybackDidStopNotficiation = @"CogPlaybackDidStopNotficiation"; - (IBAction)pause:(id)sender { - [audioPlayer pause]; + [[NSUserDefaults standardUserDefaults] setInteger:CogStatusPaused forKey:@"lastPlaybackStatus"]; + + [audioPlayer pause]; [self setPlaybackStatus: CogStatusPaused]; [self sendMetaData]; @@ -107,13 +109,17 @@ NSString *CogPlaybackDidStopNotficiation = @"CogPlaybackDidStopNotficiation"; - (IBAction)resume:(id)sender { - [audioPlayer resume]; + [[NSUserDefaults standardUserDefaults] setInteger:CogStatusPlaying forKey:@"lastPlaybackStatus"]; + + [audioPlayer resume]; } - (IBAction)stop:(id)sender { - [audioPlayer stop]; + [[NSUserDefaults standardUserDefaults] setInteger:CogStatusStopped forKey:@"lastPlaybackStatus"]; + + [audioPlayer stop]; [self sendMetaData]; } @@ -181,6 +187,8 @@ NSDictionary * makeRGInfo(PlaylistEntry *pe) DLog(@"PLAYLIST CONTROLLER: %@", [playlistController class]); [playlistController setCurrentEntry:pe]; + + lastPosition = -1; [self setPosition:[offset doubleValue]]; @@ -236,7 +244,7 @@ NSDictionary * makeRGInfo(PlaylistEntry *pe) - (void)updatePosition:(id)sender { double pos = [audioPlayer amountPlayed]; - + [self setPosition:pos]; [[playlistController currentEntry] setCurrentPosition:pos]; @@ -644,6 +652,18 @@ NSDictionary * makeRGInfo(PlaylistEntry *pe) - (void)setPosition:(double)p { + if (p == 0 || p < lastPosition || (p > lastPosition && (p - lastPosition) >= 10.0)) + { + PlaylistEntry * pe = [playlistController currentEntry]; + NSInteger lastTrackPlaying = [pe index]; + + [[NSUserDefaults standardUserDefaults] setInteger:CogStatusPlaying forKey:@"lastPlaybackStatus"]; + [[NSUserDefaults standardUserDefaults] setInteger:lastTrackPlaying forKey:@"lastTrackPlaying"]; + [[NSUserDefaults standardUserDefaults] setDouble:p forKey:@"lastTrackPosition"]; + + lastPosition = p; + } + position = p; [[playlistController currentEntry] setCurrentPosition:p];