OGeek|极客世界-中国程序员成长平台

标题: ios - AVAudioPlayer - 为什么循环之间有间隙(未压缩的音频) [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 05:47
标题: ios - AVAudioPlayer - 为什么循环之间有间隙(未压缩的音频)

NSString *path = [[NSBundle mainBundle] pathForResource"test" ofType"caf"];
audioPlayer = [[AVAudioPlayer alloc]initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
[audioPlayer setNumberOfLoops:-1];
[audioPlayer setVolume: 0.1];
[audioPlayer play];

这是我的基本代码,如果您需要了解更多信息,请告诉我。

在 iPhone 模拟器上运行时,压缩和未压缩格式都尝试了约 1 秒的间隔(没有开发许可证可在设备上运行进行测试)。

我是否遗漏了什么,我一直在搜索帖子,但我只能看到压缩音频的问题(这是有道理的)。


Xcode: 版本 6.2 (6C131e)
操作系统: OS X Yosemite 版本 10.10.2 (14C1510)
硬件: Macbook Air 13"(2014 年初)- 4GB



Best Answer-推荐答案


在这样玩之前你有没有尝试过“prepareToPlay”:

NSString *path = [[NSBundle mainBundle] pathForResource"test" ofType"caf"];
audioPlayer = [[AVAudioPlayer alloc]initWithContentsOfURL:[NSURL  fileURLWithPath:path] error:NULL];
[audioPlayer setNumberOfLoops:-1];
[audioPlayer setVolume: 0.1];
[audioPlayer prepareToPlay];
[audioPlayer play];

关于ios - AVAudioPlayer - 为什么循环之间有间隙(未压缩的音频),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29011852/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4