gpt4 book ai didi

iphone - AVAudioPlayer 有问题吗?制造延迟

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

在使用 AVAudioPlayer 时 .... 如果我单击按钮,声音不会立即播放...在那个类中,我有一个 NSTimer 不断更改图像,因此为此我必须响起声音。

但是如果我会使用这个AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath: soundPath], &soundID); ...我无法在设备中听到声音..因为我的文件是 mp3 格式。

AVAudioPlayer 代码:

NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/slotmachine.mp3", [[NSBundle mainBundle] resourcePath]]];
NSError *error;
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
audioPlayer.numberOfLoops = -1;
[audioPlayer play];

所以任何人都可以告诉我为什么我不能像 System Sound 那样流畅地使用 AVAudioPlayer .. 什么是合适的集成方式?

最佳答案

调用 [audioPlayer prepareToPlay]在您想要实际播放音频之前。

关于iphone - AVAudioPlayer 有问题吗?制造延迟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7520045/

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