I initialize an AVAudioPlayer instance:
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 */
Does anyone know why the AVAudioPlayer is not responding? Is there something that I am overlooking while initializing, playing the audioplayer? Boilerplate code maybe?
I am running this on the iPhone simulator. Also, AudioServicesPlaySystemSound() works for the same file, which is puzzling, but this indicates that sound playback might work with AVAudioPlayer as well.