Seeking: Restart output completely on track seek
This required some minor workarounds to deal with the play time counting that works toward play count reporting. Signed-off-by: Christopher Snowhill <kode54@gmail.com>
This commit is contained in:
parent
07a36873e3
commit
b8580cf193
3 changed files with 25 additions and 24 deletions
|
@ -67,6 +67,10 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)play:(NSURL *)url withUserInfo:(id)userInfo withRGInfo:(NSDictionary *)rgi startPaused:(BOOL)paused andSeekTo:(double)time {
|
- (void)play:(NSURL *)url withUserInfo:(id)userInfo withRGInfo:(NSDictionary *)rgi startPaused:(BOOL)paused andSeekTo:(double)time {
|
||||||
|
[self play:url withUserInfo:userInfo withRGInfo:rgi startPaused:paused andSeekTo:time andResumeInterval:NO];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)play:(NSURL *)url withUserInfo:(id)userInfo withRGInfo:(NSDictionary *)rgi startPaused:(BOOL)paused andSeekTo:(double)time andResumeInterval:(BOOL)resumeInterval {
|
||||||
ALog(@"Opening file for playback: %@ at seek offset %f%@", url, time, (paused) ? @", starting paused" : @"");
|
ALog(@"Opening file for playback: %@ at seek offset %f%@", url, time, (paused) ? @", starting paused" : @"");
|
||||||
|
|
||||||
[self waitUntilCallbacksExit];
|
[self waitUntilCallbacksExit];
|
||||||
|
@ -77,7 +81,7 @@
|
||||||
if(!output) {
|
if(!output) {
|
||||||
output = [[OutputNode alloc] initWithController:self previous:nil];
|
output = [[OutputNode alloc] initWithController:self previous:nil];
|
||||||
}
|
}
|
||||||
[output setup];
|
[output setupWithInterval:resumeInterval];
|
||||||
[output setVolume:volume];
|
[output setVolume:volume];
|
||||||
@synchronized(chainQueue) {
|
@synchronized(chainQueue) {
|
||||||
for(id anObject in chainQueue) {
|
for(id anObject in chainQueue) {
|
||||||
|
@ -184,28 +188,18 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)seekToTime:(double)time {
|
- (void)seekToTime:(double)time {
|
||||||
if(endOfInputReached) {
|
CogStatus status = (CogStatus)currentPlaybackStatus;
|
||||||
// This is a dirty hack in case the playback has finished with the track
|
NSURL *url;
|
||||||
// that the user thinks they're seeking into
|
id userInfo;
|
||||||
CogStatus status = (CogStatus)currentPlaybackStatus;
|
NSDictionary *rgi;
|
||||||
NSURL *url;
|
|
||||||
id userInfo;
|
|
||||||
NSDictionary *rgi;
|
|
||||||
|
|
||||||
@synchronized(chainQueue) {
|
@synchronized(chainQueue) {
|
||||||
url = [bufferChain streamURL];
|
url = [bufferChain streamURL];
|
||||||
userInfo = [bufferChain userInfo];
|
userInfo = [bufferChain userInfo];
|
||||||
rgi = [bufferChain rgInfo];
|
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];
|
|
||||||
[bufferChain seek:time];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[self play:url withUserInfo:userInfo withRGInfo:rgi startPaused:(status == CogStatusPaused) andSeekTo:time andResumeInterval:YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setVolume:(double)v {
|
- (void)setVolume:(double)v {
|
||||||
|
|
|
@ -44,6 +44,7 @@
|
||||||
- (double)secondsBuffered;
|
- (double)secondsBuffered;
|
||||||
|
|
||||||
- (void)setup;
|
- (void)setup;
|
||||||
|
- (void)setupWithInterval:(BOOL)resumeInterval;
|
||||||
- (void)process;
|
- (void)process;
|
||||||
- (void)close;
|
- (void)close;
|
||||||
- (void)seek:(double)time;
|
- (void)seek:(double)time;
|
||||||
|
|
|
@ -16,12 +16,18 @@
|
||||||
@implementation OutputNode
|
@implementation OutputNode
|
||||||
|
|
||||||
- (void)setup {
|
- (void)setup {
|
||||||
amountPlayed = 0.0;
|
[self setupWithInterval:NO];
|
||||||
amountPlayedInterval = 0.0;
|
}
|
||||||
|
|
||||||
|
- (void)setupWithInterval:(BOOL)resumeInterval {
|
||||||
|
if(!resumeInterval) {
|
||||||
|
amountPlayed = 0.0;
|
||||||
|
amountPlayedInterval = 0.0;
|
||||||
|
intervalReported = NO;
|
||||||
|
}
|
||||||
|
|
||||||
paused = YES;
|
paused = YES;
|
||||||
started = NO;
|
started = NO;
|
||||||
intervalReported = NO;
|
|
||||||
|
|
||||||
output = [[OutputCoreAudio alloc] initWithController:self];
|
output = [[OutputCoreAudio alloc] initWithController:self];
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue