gpt4 book ai didi

iphone - 在IOS核心音频中,如何找到文件播放器音频单元的真实当前播放头位置?

转载 作者:可可西里 更新时间:2023-11-01 03:59:33 25 4
gpt4 key购买 nike

我有一个程序使用文件播放器音频单元来播放、暂停和停止音频文件。我完成此操作的方法是初始化文件播放器音频单元以在位置零播放文件,然后当用户按下暂停按钮时,我停止 AUGraph,捕获当前位置,然后将该位置用作起始位置当用户按下播放按钮时。一切正常,但每隔 3 或 4 次我按下暂停键然后播放,歌曲就会在我按下暂停键之前开始播放半秒到整秒。

我不明白为什么会这样,你们有什么想法吗?这是我的代码的简化版本。

//initialize AUGraph and File player Audio unit
...
...
...

//Start AUGraph
...
...
...

// pause playback
- (void) pauseAUGraph {

//first stop the AuGrpah
result = AUGraphStop (processingGraph);

// get current play head position
AudioTimeStamp ts;
UInt32 size = sizeof(ts);

result = AudioUnitGetProperty(filePlayerUnit,
kAudioUnitProperty_CurrentPlayTime, kAudioUnitScope_Global, 0, &ts,
&size);
//save our play head position for use later
//must add it to itself to take care of multiple presses of the pause button
sampleFrameSavedPosition = sampleFrameSavedPosition + ts.mSampleTime;


//this stops the file player unit from playing
AudioUnitReset(filePlayerUnit, kAudioUnitScope_Global, 0);
NSLog (@"AudioUnitReset - stopped file player from playing");

//all done
}


// Stop playback

- (void) stopAUGraph {
// lets set the play head to zero, so that when we restart, we restart at the beginning of the file.

sampleFrameSavedPosition = 0;
//ok now that we saved the current pleayhead position, lets stop the AUGraph
result = AUGraphStop (processingGraph);
}

最佳答案

也许您应该使用数据包计数而不是时间戳,因为您只想暂停和播放音乐,而不是显示时间信息。

参见 BufferedAudioPlayer有关使用此方法的示例。

关于iphone - 在IOS核心音频中,如何找到文件播放器音频单元的真实当前播放头位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11782593/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com