gpt4 book ai didi

objective-c - OS X 上的 AVAudioPlayer 不播放任何声音

转载 作者:行者123 更新时间:2023-12-03 17:11:00 24 4
gpt4 key购买 nike

我正在尝试在 os x(不是 iOS!)上使用 AVAudioPlayer 播放声音。我正在使用以下代码:

AVAudioPlayer *player;
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:name ofType:@"mp3"];
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
player = [[AVAudioPlayer alloc] initWithContentsOfURL:
soundFileURL error:&err];

if( err ){
NSLog(@"Failed with reason: %@", [err localizedDescription]);
}
else{
player.delegate = self;
player.numberOfLoops = -1;
player.currentTime = 0;
player.volume = 1.0;
[player play];
}

一切正常,播放器调用播放函数没有错误。但之后我就听不到任何声音了。我确信我的音频文件没问题,因为我能够使用 NSSound 类播放它。我想使用 AVAudioPlayer 的原因是,当我使用 NSSound 类并且循环播放它时,中间会有短暂的暂停,这就是我想尝试的原因AVAudioPlayer

最佳答案

*player定义为属性,这样它在你的方法完成后就不会消失。

关于objective-c - OS X 上的 AVAudioPlayer 不播放任何声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28741870/

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