在 iOS 上连续播放两个音频文件并实现无缝过渡
我需要一个接一个地播放我的应用程序包(本地存储)中的音频文件,并在它们之间进行无缝转换。
使用 AVComposition 对我来说不好,因为我只知道第一个音频文件开始播放后的第二个音频文件名,所以我无法事先将它们附加在一起。
我尝试使用两个 AVAudioPlayer 并在第一个结束时启动第二个,但转换不是 100% 准确,所以我听到两者之间有(非常)小的沉默。
我认为唯一的方法是将音频分解为字节并将它们作为流播放,但我被困在这一点上(考虑到这是方向)。
有什么想法吗?
谢谢,
I am in need to play audio files that are in my apps bundle (locally stored) one after the other with a seamless transition between them.
Using an AVComposition is not good for me since I only know the second audio file name after the first has started playing and so I cant append them together before hand.
I have tried to work with two AVAudioPlayers and start the second one right when the first ends, but the transition is not 100% accurate and so I am hearing a (very) small silence between the two.
I am thinking that the only way is to break the audio into bytes and play them as stream but I am stuck at this point (considering this is the direction).
Any ideas?
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试
AVQueuePlayer
。当您在第一个音频文件开始播放后知道第二个音频文件名时,请使用以下命令获取第二个音频的资源
然后加载资产
加载完成时,将新项目添加到播放器队列中
当第一个音频播放完毕后,播放器将继续播放第二个音频。我没有尝试过,但我想不会有任何停顿。
You can try
AVQueuePlayer
.When you know the second audio file name after the first has started playing, get the asset of the second audio with
Then load the asset with
When loading completes, add new item to player queue with
When first audio completes playing, the player will continue to play the second audio. I haven't try, but I guess there will be no pause.