我有播放声音的应用程序。他们在iPad Air 10.3.1上玩得很好,但在我的iPhone 7 10.3.1上就不行了。我尝试过不同的音频格式,没有在iPhone 7上播放。在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");
}发布于 2017-05-15 18:07:40
我加了这个,现在起作用了。不知道为什么它以前在其他设备上起作用。
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryPlayback error:nil];https://stackoverflow.com/questions/43957189
复制相似问题