Added progress text to example app. Fixed finishedEvent not always being raised when user seeks to the last byte of the track
This commit is contained in:
parent
f85464236a
commit
257532c6c9
|
|
@ -47,6 +47,7 @@
|
|||
{
|
||||
@private
|
||||
NSTimer* timer;
|
||||
UILabel* label;
|
||||
UISlider* slider;
|
||||
UISwitch* repeatSwitch;
|
||||
UIButton* playButton;
|
||||
|
|
|
|||
|
|
@ -81,13 +81,18 @@
|
|||
size = CGSizeMake(80, 50);
|
||||
|
||||
repeatSwitch = [[UISwitch alloc] initWithFrame:CGRectMake((320 - size.width) / 2, frame.size.height * 0.15 + 170, size.width, size.height)];
|
||||
|
||||
label = [[UILabel alloc] initWithFrame:CGRectMake(0, slider.frame.origin.y + slider.frame.size.height, frame.size.width, 50)];
|
||||
|
||||
label.textAlignment = NSTextAlignmentCenter;
|
||||
|
||||
[self addSubview:slider];
|
||||
[self addSubview:playButton];
|
||||
[self addSubview:playFromHTTPButton];
|
||||
[self addSubview:playFromLocalFileButton];
|
||||
[self addSubview:queueShortFileButton];
|
||||
[self addSubview:repeatSwitch];
|
||||
[self addSubview:label];
|
||||
|
||||
[self setupTimer];
|
||||
[self updateControls];
|
||||
|
|
@ -120,6 +125,7 @@
|
|||
if (!audioPlayer || audioPlayer.duration == 0)
|
||||
{
|
||||
slider.value = 0;
|
||||
label.text = @"";
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
@ -128,6 +134,8 @@
|
|||
slider.maximumValue = audioPlayer.duration;
|
||||
|
||||
slider.value = audioPlayer.progress;
|
||||
|
||||
label.text = [NSString stringWithFormat:@"%@ - %@", [self formatTimeFromSeconds:audioPlayer.progress], [self formatTimeFromSeconds:audioPlayer.duration]];
|
||||
}
|
||||
|
||||
-(void) playFromHTTPButtonTouched
|
||||
|
|
@ -162,6 +170,16 @@
|
|||
}
|
||||
}
|
||||
|
||||
-(NSString*) formatTimeFromSeconds:(int)totalSeconds
|
||||
{
|
||||
|
||||
int seconds = totalSeconds % 60;
|
||||
int minutes = (totalSeconds / 60) % 60;
|
||||
int hours = totalSeconds / 3600;
|
||||
|
||||
return [NSString stringWithFormat:@"%02d:%02d:%02d", hours, minutes, seconds];
|
||||
}
|
||||
|
||||
-(void) updateControls
|
||||
{
|
||||
if (audioPlayer == nil)
|
||||
|
|
|
|||
|
|
@ -1101,6 +1101,8 @@ static void AudioQueueIsRunningCallbackProc(void* userData, AudioQueueRef audioQ
|
|||
}
|
||||
else if (entry.lastByteIndex == audioPacketsPlayedCount && entry.lastByteIndex != -1)
|
||||
{
|
||||
[self logInfo:@"handleAudioQueueOutput:lastByteIndex"];
|
||||
|
||||
BOOL everythingInBufferingQueueBuffered = YES;
|
||||
|
||||
for (int i = 0; i < bufferingQueue.count; i++)
|
||||
|
|
@ -2063,6 +2065,11 @@ static void AudioQueueIsRunningCallbackProc(void* userData, AudioQueueRef audioQ
|
|||
[currentEntry updateAudioDataSource];
|
||||
[currentEntry.dataSource seekToOffset:seekByteOffset];
|
||||
|
||||
if (self.internalState == AudioPlayerInternalStateFlushingAndStoppingButStillPlaying)
|
||||
{
|
||||
self.internalState = AudioPlayerInternalStatePlaying;
|
||||
}
|
||||
|
||||
if (seekByteOffset > 0)
|
||||
{
|
||||
discontinuous = YES;
|
||||
|
|
@ -2328,6 +2335,20 @@ static void AudioQueueIsRunningCallbackProc(void* userData, AudioQueueRef audioQ
|
|||
currentlyReadingEntry.lastFrameIndex = self->framesQueued;
|
||||
currentlyReadingEntry.lastByteIndex = audioPacketsReadCount;
|
||||
|
||||
[self logInfo:[NSString stringWithFormat:@"dataSourceEofLastByteIndex: %lld, %lld", audioPacketsReadCount, audioPacketsPlayedCount]];
|
||||
|
||||
if (audioPacketsReadCount == 0 && audioPacketsPlayedCount == audioPacketsReadCount)
|
||||
{
|
||||
[self logInfo:@"dataSourceEof shutting down audio queue"];
|
||||
|
||||
if (audioQueue)
|
||||
{
|
||||
self.internalState = AudioPlayerInternalStateFlushingAndStoppingButStillPlaying;
|
||||
|
||||
AudioQueueStop(audioQueue, NO);
|
||||
}
|
||||
}
|
||||
|
||||
currentlyReadingEntry = nil;
|
||||
}
|
||||
else
|
||||
|
|
|
|||
Loading…
Reference in New Issue