【问题标题】:Play audio files continuously with touch movements in iPhone在 iPhone 中通过触摸动作连续播放音频文件
【发布时间】: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


    【解决方案1】:

    您可能想尝试为原始音频构建混音器并使用 RemoteIO 而不是 AVPlayer API 来流式传输混音。

    【讨论】:

    • 感谢您的回复。 RemoteIO 有点复杂,我用的是 OpenAL。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多