如何在AVAudioPlayers之间交叉淡入淡出 [英] How to cross fade between AVAudioPlayers
本文介绍了如何在AVAudioPlayers之间交叉淡入淡出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用AVAudioPlayer并交叉淡入淡出超过2个mp3文件.
I want to use AVAudioPlayer and cross fade more than 2 mp3 files.
我有5个mp3文件和5个页面"myScrollView",其中包含UIScrollView类,pagedEnabled = YES.
I have 5 mp3 files and 5 pages "myScrollView" with UIScrollView class and pagingEnabled = YES.
当用户移动页面时,我想播放每个页面的每首歌曲,上一个mp3文件的音量逐渐消失,下一个mp3的音量逐渐消失.
When user move page, I want to play each songs for each page with volume fade out for previous mp3 file and fade in for next mp3.
请帮助解决此问题.
推荐答案
这是一个非常老的线程,但我只是在寻找有关交叉淡入淡出问题的解决方案并找到了它.我是这样解决的:
It's a really old thread, but I just looked for a solution concerning the cross fading issue and found it. I solved it like this:
-(void)crossFadePlayerOne:(AVAudioPlayer *)player1 andPlayerTwo:(AVAudioPlayer *)player2 withCompletion:(void(^)())completion{
if([player1 volume] > 0){
[player1 setVolume:[player1 volume] - 0.05];
[player2 setVolume:[player2 volume] + 0.05];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.1 * NSEC_PER_SEC),dispatch_get_main_queue(),^{
[self crossFadePlayerOne:player1 andPlayerTwo:player2 withCompletion:completion];
});
}else{
if(completion){
completion();
}
}
}
这篇关于如何在AVAudioPlayers之间交叉淡入淡出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文