我初始化AVAudioPlayer實例:AVAudioPlayer沒有響應
NSString* path = [[NSBundle mainBundle] pathForResource:@"foo" ofType:@"wav"];
AVAudioPlayer* player =[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:nil]; //Returned object not nil, indicating that the file has loaded successfully
BOOL b = [player prepareToPlay]; //returns TRUE
BOOL b2 = [player play];
//returns TRUE, goes immediately to the next line since asynchronous
[NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]; //wait 1 sec
printf("%10.4f\n",player.duration); //duration is 2s
printf("%10.4f\n",player.currentTime); //position remains 0
/* There is no sound output, player is also stuck since position==0 */
有誰知道爲什麼AVAudioPlayer沒有響應?在初始化,播放音頻播放器時,是否有一些我可以忽略?樣板代碼可能?
我在iPhone模擬器上運行這個。此外,AudioServicesPlaySystemSound()適用於相同的文件,這令人費解,但這表明聲音播放也可能適用於AVAudioPlayer。