Pergunta

i checked for answers but couldn't find any here is my code..i also logged to see if I'm missing something but both loggs showed up but the sound didn't play...i also imported the framework...i cant figure out what I'm doing wrong I'm a newbie please help...Thanks

- (void)viewDidLoad
{

    NSLog(@"play!");

    NSString *path = [[NSBundle mainBundle]pathForResource:@"Submarine" ofType:@"mp3"];
    AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
    [audioPlayer prepareToPlay];
    [audioPlayer play];

    NSLog(@"not playing!");
}
Foi útil?

Solução

ARC will decrease the retain count of audioPlayer as soon as viewDidLoad finishes executing. Declare audioPlayer as an instance variable, then assign in viewDidLoad to solve this issue.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top