NSString *path = [[NSBundle mainBundle] pathForResource:[arraySub objectAtIndex:indexPathHere.row] ofType:@"mp3"];
NSURL *file = [[NSURL alloc] initFileURLWithPath:path];
AVAudioPlayer *myPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:file error:nil];
self.player = myPlayer;
[player prepareToPlay];
[player setDelegate:self];
[self.player play];
NSTimeInterval lenghtMusic = player.duration;
if (player.currentTime == lenghtMusic) {
NSLog(@"It worked");
[tableThing deselectRowAtIndexPath:indexPathHere animated:YES];
[myPlayer autorelease];
[file autorelease];
}
你能看到什麼不對嗎?你能在這段代碼中看到什麼錯誤嗎?
顯然,「如果」語句來從未被調用...
是的,這是拼成長度。 :p – kennytm 2010-02-08 16:26:34
你的意思是你期望它是真實的,你永遠不會看到你的NSLog調用或條件從未被評估? – willcodejavaforfood 2010-02-08 16:27:02
您是否嘗試過調試?如果你不想/ debug /你總是可以添加一條日誌語句:NSLog(@「%d%d」,player.currentTime,lenghtMusic); //順便說一下......在你做完之後,你應該能夠看到這些值是什麼以及它們爲什麼不相等。 – Malaxeur 2010-02-08 16:27:28