Audio Unit Graph pause and repeating

不羁的心 提交于 2019-12-01 12:13:29

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.

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.

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