gpt4 book ai didi

ios - iPod touch 不播放声音

转载 作者:行者123 更新时间:2023-11-29 00:24:19 25 4
gpt4 key购买 nike

所有设备都在前台播放声音,除了 iPod touch 不在前台播放声音,当应用收到通知时,

下面我们粘贴了确切的代码

NSString *playSoundOnAlert = @"Sound.wav";
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%@",[[NSBundle mainBundle] resourcePath],playSoundOnAlert]];
NSError *error;
aVAudioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
aVAudioPlayer.numberOfLoops = 0;
[aVAudioPlayer play];

最佳答案

检查代码:

NSString *playSoundOnAlert = @"Sound";    

AVAudioPlayer *audioPlayer;

NSString *audioPath = [[NSBundle mainBundle] pathForResource: playSoundOnAlert ofType:@".wav"];
NSURL *audioURL = [NSURL fileURLWithPath:audioPath];
NSError *audioError = [[NSError alloc] init];
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:audioURL error:&audioError];

if (!audioError) {
[audioPlayer play];
NSLog(@"playing!");
}
else {
NSLog(@"Error!");
}

关于ios - iPod touch 不播放声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43471500/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com