gpt4 book ai didi

ios - 如何重复系统声音

转载 作者:行者123 更新时间:2023-12-02 23:57:43 27 4
gpt4 key购买 nike

我想重复发送到此方法的声音吗?

- (void) playSound:(CFURLRef)soundFileURLRef {
SystemSoundID soundID;
OSStatus errorCode = AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
if (errorCode != 0) {

}else{
AudioServicesPlaySystemSound(soundID);
}
}

我已经看到了有关如何使用numberOfRepeats做出答案的方法。但是我无法在我的代码中使用它。

最佳答案

尝试使用AVAudioPlayer:

- (void) playSound:(CFURLRef)soundFileURLRef {
NSError* sndErr;
AVAudioPlayer *player = [[ AVAudioPlayer alloc ] initWithContentsOfURL:(NSURL *)soundFileURLRef error:(&sndErr) ];

// at this point player has a retain count of 1. you should save it
// somewhere like a class member variable so you can stop the playing
// and release the object later. Under ARC, you must have a strong reference
// to the object so that it doesn't get released when this function goes out
// of scope.

if (sndErr != nil) {
player.numberOfLoops = -1; // infinite number of loops. call stop when you want to stop.
[player play];
}
}

关于ios - 如何重复系统声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12758680/

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