【问题标题】:AVAudioPlayer - Why is there a gap between loops (uncompressed audio)AVAudioPlayer - 为什么循环之间有间隙(未压缩的音频)
【发布时间】:2015-03-12 14:00:56
【问题描述】:
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

【问题讨论】:

  • 这可能是因为播放器需要回到开头的时间。同时检查您的音频在开头和/或结尾是否无声,这也可能给人一种感觉差距..
  • ~4 秒长,791kb 文件,无压缩且文件无静音。一个 14mb 文件压缩 5 分 46 秒文件与每个循环的 4 秒

标签: ios iphone loops audio


【解决方案1】:

在这样玩之前你有没有尝试过“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];

【讨论】:

  • 我也面临同样的问题。我试过“prepareToPlay”。但它不起作用。
【解决方案2】:

我遇到了同样的问题,我使用 AVQueuePlayer 解决了它,创建一个 AVQueuePlayer 播放器并尝试使用 mp3 媒体文件缓冲(入队)两个或三个 AVPlayerItem通过 AVPlayerActionAtItemEnd

在惰性模式下提前

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-12-21
    • 2020-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-23
    相关资源
    最近更新 更多