Reputation: 4975
I have apps that play sounds. They play fine on an iPad Air 10.3.1, but not on my iPhone 7 10.3.1. I've tried different audio formats and nothing plays on the iPhone 7. Is there some entry in the plist or some other setting I need to get sounds to play on iPhone 7?
ViewController.h
@property (strong,nonatomic) AVAudioPlayer *player;
ViewController.m
- (void)viewDidAppear:(BOOL)animated {
NSError *err;
NSURL *url = [[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle] pathForResource:@"sound" ofType:@"wav"]];
player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&err];
if (err) NSLog(@"error");
player.volume = 1.0;
player.delegate = self;
[player prepareToPlay];
[player play];
NSLog(@"sound should have played");
}
Upvotes: 0
Views: 248
Reputation: 4975
I added this and now it works. Not sure why it worked before on other devices.
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryPlayback error:nil];
Upvotes: 1