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:
Thong Nguyen
2014-01-23 12:43:22 +00:00
parent f85464236a
commit 257532c6c9
3 changed files with 40 additions and 0 deletions
+1
View File
@@ -47,6 +47,7 @@
{
@private
NSTimer* timer;
UILabel* label;
UISlider* slider;
UISwitch* repeatSwitch;
UIButton* playButton;
+18
View File
@@ -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)