【发布时间】:2011-10-25 12:28:58
【问题描述】:
当触摸在 iPhone 屏幕上移动时,我正在尝试播放连续的音频剪辑。根据屏幕区域有特定的音频剪辑。当触摸更改其区域时,先前的音频会淡出,而(新区域的)新剪辑会淡入。
在- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 方法中,我正在检测区域变化并调用[self playSoundForRect] 方法。方法如下:
-(void)playSoundWithPath
{
[self fadeVolume];
NSString *audioPath;
switch (curRect) // curRect is the Currently entered region
{
case 1:
audioPath = [[NSBundle mainBundle] pathForResource:@"clip1" ofType:@"mp3"];
break;
case 2:
audioPath = [[NSBundle mainBundle] pathForResource:@"clip2" ofType:@"mp3"];
break;
case 3:
audioPath = [[NSBundle mainBundle] pathForResource:@"clip3" ofType:@"mp3"];
break;
case 4:
audioPath = [[NSBundle mainBundle] pathForResource:@"clip4" ofType:@"mp3"];
break;
default:
break;
}
theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:audioPath] error:NULL];
theAudio.delegate = self;
[theAudio play];
}
-(void)fadeVolume
{
if (theAudio.volume > 0.1)
{
theAudio.volume -= 0.1;
[self performSelector:@selector(fadeVolume) withObject:nil afterDelay:0.1];
}
else
{
[theAudio stop];
}
}
但是代码不能正常工作。如何正确混合输入和输出剪辑,使它们感觉流畅和连续?欢迎任何形式的建议。
【问题讨论】:
标签: iphone touch avaudioplayer fadein fadeout