Audio Unit Graph pause and repeating

浪尽此生 提交于 2019-12-04 02:15:57

问题


I've been trying to implement Audio Unit Graph using Apple provided code: IphoneMixerEQGraphTest. So far I have encountered two problems:

1.) I can't find any way to pause playing

2.) Provided example repeats endlessly. Is There a way I can disable repeat or or stop it - using a timer, intercept some kind of buffer value, when playing is almost at the end?

Thank You.


回答1:


NO REPEATING FUNCTIONALITY

So far I have found a way to deal with audio stopping - although it's not pretty:

I load same audio file in AVAudioPlayer - and get from it sound file duration. Then, using

performSelector:withObject:afterDelay: 

I can stop AUGraph when sound file should end playing.

PAUSE AUGRAPH FUNCTIONALITY

It turns out that implementing pause is pretty simple. While AUGraph data source is not changed - by calling

[graphController startAUGraph]; or [graphController stopAUGraph];

will only pause/resume playing.

Although this affects performSelector timer. So, to use both - pause/no-repeating possibilities, one should use NSTimer - when AUGraph paused - then timer pauses too. When AUGraph resumed - timer resumes counting, and when it reaches provided sound file duration - it stops playing.

Bottom line

By using duration value from AVAudioPlayer (or any other player which provides duration) - it is possible to implement AUGraph sound player with play/pause/stop (no-repeat/repeat)/next song/previous song/ functions + EQUALIZER.




回答2:


AVAudioPlayer is a huge class, You can easily get duration from:

Float64 fileDuration = PrepareFileAU (fileAU, fileFormat, audioFile);

see ADC sample at:

http://developer.apple.com/library/mac/#samplecode/PlayFile/Introduction/Intro.html

avoiding including other frameworks.



来源:https://stackoverflow.com/questions/7977777/audio-unit-graph-pause-and-repeating

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!