alexbw / novocaine

Painless high-performance audio on iOS and Mac OS X
http://alexbw.github.com/novocaine/
MIT License
2.23k stars 273 forks source link

Cannot stop playback #47

Closed borut-t closed 11 years ago

borut-t commented 11 years ago

Hello,

is there a way to stop currently playing audio? I've tried this

[audioManager pause];

... and this

[fileReader stop];

Both are not good solutions. The first one stop playing fine but cannot play it again. Second doesn't really stops playing. It just stops file reader.

I've also tried to put stop handler into setOutputBlock

[self.audioManager setOutputBlock:^(float *data, UInt32 numFrames, UInt32 numChannels) {
    if (stopPlaying) {
        return;
    }
    ...
}

Is there any good solution to stop/play/resume audio playback?

mihael commented 11 years ago

just don't output anything in the block when You don't want to playback, something like this:

[audioManager setOutputBlock:^(float *data, UInt32 numFrames, UInt32 numChannels) {

    if (isPlaying) {
        if (!fileReader) {
            fileReader = [[AudioFileReader alloc]
                          initWithAudioFileURL:inputFileURL
                          samplingRate:audioManager.samplingRate
                          numChannels:audioManager.numOutputChannels];
            [fileReader play];
            playTime = [fileReader getDuration];
        }
        [fileReader retrieveFreshAudio:data numFrames:numFrames numChannels:numChannels];
    } else {
        if (fileReader) {
            [fileReader release];
            fileReader = nil;
        }
    }
borut-t commented 11 years ago

@mihael Thanks!