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.
Trying to play sound using the <AVFoundation/AVFoundation.h> framework
-
11-06-2023 - |
質問
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!");
}
解決
所属していません StackOverflow