Cog Audio: Properly support seeking within the file that appears to be playing, even if it has already finished decoding

CQTexperiment
Christopher Snowhill 2022-01-14 00:29:02 -08:00
parent 083dbbf18b
commit 5aa3f7dd0a
2 changed files with 30 additions and 6 deletions

View File

@ -39,6 +39,8 @@
atomic_bool resettingNow; atomic_bool resettingNow;
atomic_int refCount; atomic_int refCount;
int currentPlaybackStatus;
} }
- (id)init; - (id)init;

View File

@ -158,11 +158,31 @@
- (void)seekToTime:(double)time - (void)seekToTime:(double)time
{ {
//Need to reset everything's buffers, and then seek? if (endOfInputReached)
/*HACK TO TEST HOW WELL THIS WOULD WORK*/ {
// This is a dirty hack in case the playback has finished with the track
// that the user thinks they're seeking into
CogStatus status = (CogStatus) currentPlaybackStatus;
NSURL *url;
id userInfo;
NSDictionary *rgi;
@synchronized (chainQueue) {
url = [bufferChain streamURL];
userInfo = [bufferChain userInfo];
rgi = [bufferChain rgInfo];
}
[self stop];
[self play:url withUserInfo:userInfo withRGInfo:rgi startPaused:(status == CogStatusPaused) andSeekTo:time];
}
else
{
// Still decoding the current file, safe to seek within it
[output seek:time]; [output seek:time];
[bufferChain seek:time]; [bufferChain seek:time];
/*END HACK*/ }
} }
- (void)setVolume:(double)v - (void)setVolume:(double)v
@ -447,6 +467,8 @@
- (void)setPlaybackStatus:(int)status waitUntilDone:(BOOL)wait - (void)setPlaybackStatus:(int)status waitUntilDone:(BOOL)wait
{ {
currentPlaybackStatus = status;
[self sendDelegateMethod:@selector(audioPlayer:didChangeStatus:userInfo:) withObject:[NSNumber numberWithInt:status] withObject:[bufferChain userInfo] waitUntilDone:wait]; [self sendDelegateMethod:@selector(audioPlayer:didChangeStatus:userInfo:) withObject:[NSNumber numberWithInt:status] withObject:[bufferChain userInfo] waitUntilDone:wait];
} }