Made resume playback on startup so that seeking operation is entirely atomic with starting playback, so the new seeking behavior doesn't have the potential to crash the player

CQTexperiment
Christopher Snowhill 2021-12-26 04:35:54 -08:00
parent 1cc34ea7d4
commit 917b7457b6
5 changed files with 34 additions and 9 deletions

View File

@ -180,8 +180,7 @@ void* kAppControllerContext = &kAppControllerContext;
if (lastStatus != CogStatusStopped && lastIndex >= 0)
{
[playbackController playEntryAtIndex:lastIndex startPaused:(lastStatus == CogStatusPaused)];
[playbackController seek:[NSNumber numberWithDouble:[[NSUserDefaults standardUserDefaults] floatForKey:@"lastTrackPosition"]]];
[playbackController playEntryAtIndex:lastIndex startPaused:(lastStatus == CogStatusPaused) andSeekTo:[NSNumber numberWithDouble:[[NSUserDefaults standardUserDefaults] floatForKey:@"lastTrackPosition"]]];
}
}

View File

@ -77,8 +77,10 @@ extern NSDictionary * makeRGInfo(PlaylistEntry *pe);
- (void)playEntryAtIndex:(NSInteger)i;
- (void)playEntryAtIndex:(NSInteger)i startPaused:(BOOL)paused;
- (void)playEntryAtIndex:(NSInteger)i startPaused:(BOOL)paused andSeekTo:(id)offset;
- (void)playEntry:(PlaylistEntry *)pe;
- (void)playEntry:(PlaylistEntry *)pe startPaused:(BOOL)paused;
- (void)playEntry:(PlaylistEntry *)pe startPaused:(BOOL)paused andSeekTo:(id)offset;
// Playlist notifications
- (void)playlistDidChange:(PlaylistController *)p;

View File

@ -117,14 +117,21 @@ NSString *CogPlaybackDidStopNotficiation = @"CogPlaybackDidStopNotficiation";
//called by double-clicking on table
- (void)playEntryAtIndex:(NSInteger)i
{
[self playEntryAtIndex:i startPaused:NO];
[self playEntryAtIndex:i startPaused:NO andSeekTo:[NSNumber numberWithDouble:0.0]];
}
- (void)playEntryAtIndex:(NSInteger)i startPaused:(BOOL)paused
{
PlaylistEntry *pe = [playlistController entryAtIndex:i];
[self playEntry:pe startPaused:paused andSeekTo:[NSNumber numberWithDouble:0.0]];
}
- (void)playEntryAtIndex:(NSInteger)i startPaused:(BOOL)paused andSeekTo:(id)offset
{
PlaylistEntry *pe = [playlistController entryAtIndex:i];
[self playEntry:pe startPaused:paused];
[self playEntry:pe startPaused:paused andSeekTo:offset];
}
@ -155,10 +162,15 @@ NSDictionary * makeRGInfo(PlaylistEntry *pe)
- (void)playEntry:(PlaylistEntry *)pe
{
[self playEntry:pe startPaused:NO];
[self playEntry:pe startPaused:NO andSeekTo:[NSNumber numberWithDouble:0.0]];
}
- (void)playEntry:(PlaylistEntry *)pe startPaused:(BOOL)paused
{
[self playEntry:pe startPaused:paused andSeekTo:[NSNumber numberWithDouble:0.0]];
}
- (void)playEntry:(PlaylistEntry *)pe startPaused:(BOOL)paused andSeekTo:(id)offset
{
if (playbackStatus != CogStatusStopped && playbackStatus != CogStatusStopping)
[self stop:self];
@ -166,7 +178,7 @@ NSDictionary * makeRGInfo(PlaylistEntry *pe)
DLog(@"PLAYLIST CONTROLLER: %@", [playlistController class]);
[playlistController setCurrentEntry:pe];
[self setPosition:0.0];
[self setPosition:[offset doubleValue]];
if (pe == nil)
return;
@ -198,7 +210,7 @@ NSDictionary * makeRGInfo(PlaylistEntry *pe)
[self sendMetaData];
[audioPlayer play:[pe URL] withUserInfo:pe withRGInfo:makeRGInfo(pe) startPaused:paused];
[audioPlayer play:[pe URL] withUserInfo:pe withRGInfo:makeRGInfo(pe) startPaused:paused andSeekTo:[offset doubleValue]];
}
- (IBAction)next:(id)sender

View File

@ -46,6 +46,7 @@
- (void)play:(NSURL *)url;
- (void)play:(NSURL *)url withUserInfo:(id)userInfo withRGInfo:(NSDictionary*)rgi;
- (void)play:(NSURL *)url withUserInfo:(id)userInfo withRGInfo:(NSDictionary*)rgi startPaused:(BOOL)paused;
- (void)play:(NSURL *)url withUserInfo:(id)userInfo withRGInfo:(NSDictionary*)rgi startPaused:(BOOL)paused andSeekTo:(double)time;
- (void)play:(id<CogDecoder>)decoder startPaused:(BOOL)paused;
- (void)stop;

View File

@ -45,15 +45,20 @@
- (void)play:(NSURL *)url
{
[self play:url withUserInfo:nil withRGInfo:nil startPaused:NO];
[self play:url withUserInfo:nil withRGInfo:nil startPaused:NO andSeekTo:0.0];
}
- (void)play:(NSURL *)url withUserInfo:(id)userInfo withRGInfo:(NSDictionary *)rgi
{
[self play:url withUserInfo:userInfo withRGInfo:rgi startPaused:NO];
[self play:url withUserInfo:userInfo withRGInfo:rgi startPaused:NO andSeekTo:0.0];
}
- (void)play:(NSURL *)url withUserInfo:(id)userInfo withRGInfo:(NSDictionary *)rgi startPaused:(BOOL)paused
{
[self play:url withUserInfo:userInfo withRGInfo:rgi startPaused:paused andSeekTo:0.0];
}
- (void)play:(NSURL *)url withUserInfo:(id)userInfo withRGInfo:(NSDictionary *)rgi startPaused:(BOOL)paused andSeekTo:(double)time
{
if (output) {
[output close];
@ -109,6 +114,12 @@
[bufferChain setUserInfo:userInfo];
if (time > 0.0)
{
[output seek:time];
[bufferChain seek:time];
}
[self setShouldContinue:YES];
outputLaunched = NO;