iPhone 7 iOS 10 上没有播放声音
Sounds not playing on iPhone 7 iOS 10
我有播放声音的应用程序。它们在 iPad Air 10.3.1 上运行良好,但在我的 iPhone 7 10.3.1 上运行不佳。我尝试了不同的音频格式,但 iPhone 7 上没有播放任何内容。plist 中是否有一些条目或其他设置我需要让声音在 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");
}
我添加了这个,现在可以使用了。不确定为什么它以前在其他设备上有效。
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryPlayback error:nil];
我有播放声音的应用程序。它们在 iPad Air 10.3.1 上运行良好,但在我的 iPhone 7 10.3.1 上运行不佳。我尝试了不同的音频格式,但 iPhone 7 上没有播放任何内容。plist 中是否有一些条目或其他设置我需要让声音在 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");
}
我添加了这个,现在可以使用了。不确定为什么它以前在其他设备上有效。
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryPlayback error:nil];