AudioStreamer doesn't show the correct play Time

977 views Asked by At

i've one ios application that plays music by streaming and using the mattgallagher AudioStreamer library it doesn't show the real playtime and never stop play at 0 secs...

Does anyone know why this happens??

Thanks a lot!

2

There are 2 answers

3
Philipp Schlösser On

I experienced something similar. Have a look at the progress method in AudioStreamer.m

- (double)progress
{
    @synchronized(self)
    {
        if (sampleRate > 0) && ![self isFinishing])
        {
            if (state != AS_PLAYING && state != AS_PAUSED && state != AS_BUFFERING)
            {
                return lastProgress;
            }
    ...
        }
    }

    return lastProgress;
}

Now, the reason for the progress not being displayed correctly lies within the two if-statements. When your AudioStreamer is nearly finished (probably when all data is loaded), it's isFinishing becomes true, which makes it return the cached value for progress. Also, the streamer state becomes AS_STOPPING, which makes the second if-statement return the lastProgress. What you really want is to update the progress right until the streamer stops.

My following modification to the code does this and it seems to work fine. HOWEVER, given the general quality of the AudioStreamer and the fact that it's developed by Matt Gallagher, those if statements might be as they are for a reason. So far, I did not experience any crashes or alike with my modified code but you should thoroughly test it in your app. Note, that, once the streamer is done, I don't query the progress anymore. If you do, test if it works :)

- (double)progress
{
    @synchronized(self)
    {
        if (sampleRate > 0))
        {
            if (state != AS_PLAYING && state != AS_PAUSED && state != AS_BUFFERING && state != AS_STOPPING)
            {
                return lastProgress;
            }
    ...
        }
    }

    return lastProgress;
}
0
Say2Manuj On