Skip to content

Commit

Permalink
make sure progress is updated even if paused
Browse files Browse the repository at this point in the history
If the window becomes unoccluded, resuming the timer, it won't update
the progress if paused, because the timer bails early to avoid doing
spurious work. In this case, we do want the update, so just call that
inner part of code before we install the timer.
  • Loading branch information
NattyNarwhal committed Nov 2, 2023
1 parent 2781e3e commit 2e38c90
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions Submariner/SBDatabaseController.m
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,27 @@ - (void)uninstallProgressTimer {
progressUpdateTimer = nil;
}

/// Updates the progress slider, without any preconditions.
- (void)updateProgress {

[progressSlider setEnabled:YES];
NSString *currentTimeString = [[SBPlayer sharedInstance] currentTimeString];
NSString *remainingTimeString = [[SBPlayer sharedInstance] remainingTimeString];
double progress = [[SBPlayer sharedInstance] progress];

if(currentTimeString)
[progressTextField setStringValue:currentTimeString];

if(remainingTimeString)
[durationTextField setStringValue:remainingTimeString];

if(progress > 0)
[progressSlider setDoubleValue:progress];

// If buffering is useful to know, we could reimplement it better someday.

}

- (void)updateProgress:(NSTimer *)updatedTimer {

if([[SBPlayer sharedInstance] isPlaying]) {
Expand All @@ -988,22 +1009,7 @@ - (void)updateProgress:(NSTimer *)updatedTimer {
return;
}

[progressSlider setEnabled:YES];
NSString *currentTimeString = [[SBPlayer sharedInstance] currentTimeString];
NSString *remainingTimeString = [[SBPlayer sharedInstance] remainingTimeString];
double progress = [[SBPlayer sharedInstance] progress];

if(currentTimeString)
[progressTextField setStringValue:currentTimeString];

if(remainingTimeString)
[durationTextField setStringValue:remainingTimeString];

if(progress > 0)
[progressSlider setDoubleValue:progress];

// If buffering is useful to know, we could reimplement it better someday.

[self updateProgress];
} else {
[self clearPlaybackProgress];
}
Expand Down Expand Up @@ -1389,6 +1395,8 @@ - (void)windowDidChangeOcclusionState:(NSNotification *)notification {
BOOL visible = self.window.occlusionState & NSWindowOcclusionStateVisible;
BOOL playing = [[SBPlayer sharedInstance] isPlaying];
if (visible && playing) {
// call updateProgress to always update, as updateProgress: from the timer will bail early if paused
[self updateProgress];
[self installProgressTimer];
}
else {
Expand All @@ -1401,7 +1409,6 @@ - (void)windowDidChangeOcclusionState:(NSNotification *)notification {




#pragma mark -
#pragma mark Player Notifications (Private)

Expand Down

0 comments on commit 2e38c90

Please sign in to comment.