1
我正在開發一款iOS音頻播放器,並且我想實現一個進度條,用於指示正在播放的當前歌曲的進度。 在我的ViewController類中,我有兩個雙重實例 - 時間和持續時間,以及一個名爲background的AVAudioPlayer實例。更新iOS 5中的進度條
- (IBAction)play:(id)sender {
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"some_song" ofType:@"mp3"];
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:filePath];
background = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:nil];
background.delegate = self;
[background setNumberOfLoops:1];
[background setVolume:0.5];
[background play];
time = 0;
duration = [background duration];
while(time < duration){
[progressBar setProgress: (double) time/duration animated:YES];
time += 1;
}
}
任何人都可以解釋我做錯了什麼? 在此先感謝。
非常感謝你,它的工作原理! ;-) – nemesis 2012-03-13 19:28:57