在 iPhone 中通过触摸动作连续播放音频文件
当触摸在 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];
}
}
但是代码无法正常工作。如何正确混合 in &出剪辑,使它们感觉光滑&连续的?欢迎任何建议。
I'm trying to play continuous audio clippings when touch moves across the screen of iPhone. There are specific audio clippings according to the screen regions. When touch changes its region the previous audio fades out & the new clip (of the new region) fades in.
In - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
method I'm detecting the region change & calling the [self playSoundForRect]
method. Here is the method:
-(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];
}
}
But the code is not working properly. How to properly mix the in & out clips, so that they feel smooth & continuous? Any kind of suggesion is welcome.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能想尝试构建原始音频混音器并使用 RemoteIO 而不是 AVPlayer API 来流式传输混音。
You might want to try building a mixer for raw audio and use RemoteIO instead of the AVPlayer API to stream the mix.