在iPhone Mixer EQGraph Test中使用AUGraph转发一首歌

时间:2014-04-24 11:22:35

标签: ios objective-c

我正在使用AUGraph实现一个玩家(来自iPhonemixerEQgraphtest的示例)。我已经实现了转到下一首和之前的歌曲。但从昨天开始,我一直在使用UISlider在播放器中进行前进选项。任何人都可以告诉我如何实施前进选项。为了更好地理解,我已经包含了图像。

例如:如果我将滑块滑动到10秒,则必须从第10秒开始播放歌曲。任何想法/建议都可能非常好

enter image description here

1 个答案:

答案 0 :(得分:1)

经过长时间的研究,我找到了解决方案

在AUGraphController.mm中,我更改了此代码

// the render notification is used to keep track of the frame number position in the source audio
static OSStatus renderNotification(void *inRefCon, AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList *ioData)
{
    Simple_PlayerAppDelegate *appDel = (Simple_PlayerAppDelegate*)[[UIApplication sharedApplication] delegate];

    SourceAudioBufferDataPtr userData = (SourceAudioBufferDataPtr)inRefCon;
    //NSLog(@"userdata out is %lu",(userData->frameNum/44100));

    appDel.secondsFromLocalSong = (userData->frameNum/44100);

    if (*ioActionFlags & kAudioUnitRenderAction_PostRender)
    {

        //printf("post render notification frameNum %ld inNumberFrames %ld\n", userData->frameNum, inNumberFrames);

        if(appDel.skipSecondsFromLocalSong>0)
        {
            userData->frameNum = (appDel.skipSecondsFromLocalSong*userData->maxNumFrames);
            appDel.skipSecondsFromLocalSong = 0;
        }
        else
            userData->frameNum += inNumberFrames;

        if (userData->frameNum >= userData->maxNumFrames) {
            //userData->frameNum = 0;
            SilenceData(ioData);
        }
    }

    return noErr;
}