tumtumtum / StreamingKit

A fast and extensible gapless AudioPlayer/AudioStreamer for OSX and iOS (iPhone, iPad)
Other
2.43k stars 525 forks source link

Last played buffer playing before new track. #432

Open zsaraf opened 5 years ago

zsaraf commented 5 years ago

Hello,

I am building an Icecast streaming radio app that streams from a few different URLs. This issue doesn't arise on the first time that I call STKAudioPlayer.play. But every time I call STKAudioPlayer.play on the player after the first stream is played and stopped, I hear a tiny bit of the last stream before I hear the new stream. Just a tiny bit (around ~500ms), but it makes for a very bad user experience.

For reference, this is how I call play and stop:

- (void)startStreamWithUrl:(NSString *)streamUrl
{
    [self->_audioPlayer play:streamUrl];
}

- (void)stopStream
{
    [self->_audioPlayer stop];
}

An example URL that might be passed in to startStreamWithUrl: could be: http://ss.deprogrammedradio.com:8000/deprogrammedradio.mp3

Calling [self->_audioPlayer stop] is supposed to clear out all of the old buffers, but it doesn't seem like this is fully happening.

Anyone have any idea where I should look?

Thanks. Zach

iOkay commented 4 years ago

I have the same issue. I solved it by removing code involved 'playbackRateUnitDescription'.

iOkay commented 4 years ago

I have the same issue. I solved it by removing code involved 'playbackRateUnitDescription'.

But the rate property will not work.

iDevelopper commented 4 years ago

When the user change the stream, I create a new STKAudioPlayer:

    func newAudioPlayer() {
        if let audioPlayer = self.audioPlayer {
            audioPlayer.dispose()
            self.audioPlayer = nil
        }

        var options = STKAudioPlayerOptions()
        options.flushQueueOnSeek = false
        options.enableVolumeMixer = true

        options.equalizerBandFrequencies = (32, 64, 125, 250, 500, 1000, 2000, 4000, 8000, 16000, 0, 0, 0, 0, 0, 0 , 0, 0, 0, 0, 0, 0, 0, 0)

        self.audioPlayer = STKAudioPlayer(options: options)
        self.audioPlayer.delegate = self
        self.audioPlayer.meteringEnabled = false
        self.audioPlayer.equalizerEnabled = true
        self.audioPlayer.volume = 1

        for i in 0..<self.frequencyPlotView.gains.count {
            self.audioPlayer.setGain((self.frequencyPlotView.gains[i] as! NSNumber).floatValue, forEqualizerBand: Int32(i))
        }

        self.audioPlayer.appendFrameFilter(withName: "CustomEQFilter") { (channelsPerFrame, bytesPerFrame, frameCount, frames) in

            guard self.frequencyAnalyzer != nil else {return}

            let description = AudioStreamPacketDescription(mStartOffset: 0, mVariableFramesInPacket: 0, mDataByteSize: bytesPerFrame * frameCount)

            self.frequencyAnalyzer.audioPlayer(self.audioPlayer, samplesAvailable: frames, description: description)
        }
    }
AlexeyKolmyk commented 4 years ago

Good day! I have the same problem, but I have some requirements:

Does anyone have solutions/suggestions how this problem can be fixed?

AlexeyKolmyk commented 4 years ago

After several days I've found a solution. I need to reset audiounit state on pause:

OOStatus error = AudioUnitReset(playbackRateUnit, kAudioUnitScope_Global, 0);