diff --git a/Application/AppController.m b/Application/AppController.m index 41136cd3b..586b36b28 100644 --- a/Application/AppController.m +++ b/Application/AppController.m @@ -284,7 +284,7 @@ increase/decrease as long as the user holds the left/right, plus/minus button */ if (lastStatus != kCogStatusStopped && lastIndex >= 0) { - [playbackController playEntryAtIndex:lastIndex]; + [playbackController playEntryAtIndex:lastIndex startPaused:(lastStatus == kCogStatusPaused)]; [playbackController seek:[NSNumber numberWithDouble:[[NSUserDefaults standardUserDefaults] floatForKey:@"lastTrackPosition"]]]; } diff --git a/Application/PlaybackController.h b/Application/PlaybackController.h index 6dd124768..6ad2615f7 100644 --- a/Application/PlaybackController.h +++ b/Application/PlaybackController.h @@ -72,7 +72,9 @@ extern NSDictionary * makeRGInfo(PlaylistEntry *pe); - (void)audioFadeUp:(NSTimer *)audioTimer; - (void)playEntryAtIndex:(int)i; +- (void)playEntryAtIndex:(int)i startPaused:(BOOL)paused; - (void)playEntry:(PlaylistEntry *)pe; +- (void)playEntry:(PlaylistEntry *)pe startPaused:(BOOL)paused; // Playlist notifications - (void)playlistDidChange:(PlaylistController *)p; diff --git a/Application/PlaybackController.m b/Application/PlaybackController.m index 0496f902d..6953b4267 100644 --- a/Application/PlaybackController.m +++ b/Application/PlaybackController.m @@ -104,10 +104,15 @@ NSString *CogPlaybackDidStopNotficiation = @"CogPlaybackDidStopNotficiation"; //called by double-clicking on table - (void)playEntryAtIndex:(int)i +{ + [self playEntryAtIndex:i startPaused:NO]; +} + +- (void)playEntryAtIndex:(int)i startPaused:(BOOL)paused { PlaylistEntry *pe = [playlistController entryAtIndex:i]; - [self playEntry:pe]; + [self playEntry:pe startPaused:paused]; } @@ -137,6 +142,11 @@ NSDictionary * makeRGInfo(PlaylistEntry *pe) } - (void)playEntry:(PlaylistEntry *)pe +{ + [self playEntry:pe startPaused:NO]; +} + +- (void)playEntry:(PlaylistEntry *)pe startPaused:(BOOL)paused { if (playbackStatus != kCogStatusStopped) [self stop:self]; @@ -154,7 +164,7 @@ NSDictionary * makeRGInfo(PlaylistEntry *pe) [pe performSelectorOnMainThread:@selector(setMetadata:) withObject:[playlistLoader readEntryInfo:pe] waitUntilDone:YES]; } - [audioPlayer play:[pe URL] withUserInfo:pe withRGInfo:makeRGInfo(pe)]; + [audioPlayer play:[pe URL] withUserInfo:pe withRGInfo:makeRGInfo(pe) startPaused:paused]; } - (IBAction)next:(id)sender @@ -187,6 +197,8 @@ NSDictionary * makeRGInfo(PlaylistEntry *pe) double time = [sender doubleValue]; [audioPlayer seekToTime:time]; + + [self setPosition:time]; [[playlistController currentEntry] setCurrentPosition:time]; } diff --git a/Audio/AudioPlayer.h b/Audio/AudioPlayer.h index 6d6da3ecc..daafc08d2 100644 --- a/Audio/AudioPlayer.h +++ b/Audio/AudioPlayer.h @@ -28,6 +28,8 @@ BOOL outputLaunched; BOOL endOfInputReached; + BOOL startedPaused; + BOOL initialBufferFilled; } - (id)init; @@ -37,6 +39,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)stop; - (void)pause; diff --git a/Audio/AudioPlayer.m b/Audio/AudioPlayer.m index 3e81b2a64..0788928cb 100644 --- a/Audio/AudioPlayer.m +++ b/Audio/AudioPlayer.m @@ -45,10 +45,15 @@ - (void)play:(NSURL *)url { - [self play:url withUserInfo:nil withRGInfo:nil]; + [self play:url withUserInfo:nil withRGInfo:nil startPaused:NO]; } - (void)play:(NSURL *)url withUserInfo:(id)userInfo withRGInfo:(NSDictionary *)rgi +{ + [self play:url withUserInfo:userInfo withRGInfo:rgi startPaused:NO]; +} + +- (void)play:(NSURL *)url withUserInfo:(id)userInfo withRGInfo:(NSDictionary *)rgi startPaused:(BOOL)paused { if (output) { @@ -101,8 +106,13 @@ [self setShouldContinue:YES]; outputLaunched = NO; + startedPaused = paused; + initialBufferFilled = NO; [bufferChain launchThreads]; + + if (paused) + [self setPlaybackStatus:kCogStatusPaused waitUntilDone:YES]; } - (void)stop @@ -121,6 +131,13 @@ - (void)resume { + if (startedPaused) + { + startedPaused = NO; + if (initialBufferFilled) + [self launchOutputThread]; + } + [output resume]; [self setPlaybackStatus:kCogStatusPlaying waitUntilDone:YES]; @@ -200,7 +217,8 @@ - (void)launchOutputThread { - if (outputLaunched == NO) { + initialBufferFilled = YES; + if (outputLaunched == NO && startedPaused == NO) { [self setPlaybackStatus:kCogStatusPlaying]; [output launchThread]; outputLaunched = YES; diff --git a/Playlist/PlaylistController.h b/Playlist/PlaylistController.h index e50cfa758..8aa900826 100644 --- a/Playlist/PlaylistController.h +++ b/Playlist/PlaylistController.h @@ -75,7 +75,6 @@ typedef enum { - (IBAction)toggleRepeat:(id)sender; -- (IBAction)sortByPath; - (IBAction)randomizeList:(id)sender; - (IBAction)showEntryInFinder:(id)sender; diff --git a/Playlist/PlaylistController.m b/Playlist/PlaylistController.m index 8142ae72c..747a8c7a1 100644 --- a/Playlist/PlaylistController.m +++ b/Playlist/PlaylistController.m @@ -299,7 +299,7 @@ - (void)insertObjects:(NSArray *)objects atArrangedObjectIndexes:(NSIndexSet *)indexes { [[[self undoManager] prepareWithInvocationTarget:self] removeObjectsAtArrangedObjectIndexes:indexes]; - NSString *actionName = [NSString stringWithFormat:@"Adding %d entries", [objects count]]; + NSString *actionName = [NSString stringWithFormat:@"Adding %lu entries", (unsigned long)[objects count]]; [[self undoManager] setActionName:actionName]; [super insertObjects:objects atArrangedObjectIndexes:indexes]; @@ -312,7 +312,7 @@ { NSArray *objects = [[self content] objectsAtIndexes:indexes]; [[[self undoManager] prepareWithInvocationTarget:self] insertObjects:objects atArrangedObjectIndexes:indexes]; - NSString *actionName = [NSString stringWithFormat:@"Removing %d entries", [indexes count]]; + NSString *actionName = [NSString stringWithFormat:@"Removing %lu entries", (unsigned long)[indexes count]]; [[self undoManager] setActionName:actionName]; DLog(@"Removing indexes: %@", indexes);