ofSoundPlayer::getIsPlaying() does not work with mp3 #1361

Closed
prossel opened this Issue Jun 28, 2012 · 3 comments

Comments

Projects
None yet
3 participants

prossel commented Jun 28, 2012

Looks like getIsPlaying is always returning false if the sound is a .mp3 file. Tested with OF71 on iOS.

To reproduce:

  1. use the soundPlayerExample
  2. drop a .mp3 file in the sounds folder
  3. change the filename in testApp.mm: synth.loadSound("sounds/part1.mp3");
  4. run the app
  5. click to start playing sounds

When the last two sounds are playing, their title turns red.

The first sound (mp3) does not turn red because getIsPlaying() returns false.

prossel commented Jun 30, 2012

I don't have the time now to fork and make a pull-request, but here is how I fixed it. These are stupid code snippets instead of a nice diff, but time runs and I have a deadline approaching. Probably usefull anyways to someone willing to fix the problem.

Look for the lines marked with ///PR

ofxOpenALSoundPlayer.cpp

bool ofxOpenALSoundPlayer::update() {

    bool deletedAnything = false;

    if (!iAmAnMp3) { ///PR

        for(int i=retainedBuffers.size()-1;i>=0;i--) {
            if(SoundEngine_Update(retainedBuffers[i]->primedID, retainedBuffers[i]->buffer)) {
                deleteretainedBuffers[i];
                retainedBuffers.erase(retainedBuffers.begin()+i);
                deletedAnything = true;
            }
        }

        if(retainedBuffers.size()==0)
        {
            myPrimedId=-1;
            stopped=true;
        }
    }

    return deletedAnything;
}

This will almost fix it, but getIsPlaying will return false little before the end of the sound. I guess when last buffer is sent. To fully fix it, we need to modify SoundEngine.cpp as well.

SoundEngine.cpp

BackgroundTrackMgr() 
:mQueue(0),
mBufferByteSize(0),
mCurrentPacket(0),
mNumPacketsToRead(0),
mVolume(1.0),
mPacketDescs(NULL),
mCurrentFileIndex(0),
mMakeNewQueueWhenStopped(false),
mStopAtEnd(false),
mStopped(true){ } ///PR

----

staticvoid QueueStoppedProc(void *                  inUserData,
AudioQueueRef          inAQ,
AudioQueuePropertyID    inID)
{
            printf("QueueStoppedProc\n");
UInt32 isRunning;
UInt32 propSize = sizeof(isRunning);

BackgroundTrackMgr *THIS = (BackgroundTrackMgr*)inUserData;
OSStatus result = AudioQueueGetProperty(inAQ, kAudioQueueProperty_IsRunning, &isRunning, &propSize);

            THIS->mStopped = !isRunning; ///PR

----

staticvoid QueueCallback(void *inUserData,
AudioQueueRefinAQ,
AudioQueueBufferRefinCompleteAQBuffer) 
{
// dispose of the buffer if no longer in use
OSStatus result = noErr;
BackgroundTrackMgr *THIS = (BackgroundTrackMgr*)inUserData;
if (DisposeBuffer(inAQ, THIS->mBuffersToDispose, inCompleteAQBuffer))
    return;

if (THIS->mStopped){
    //return; ///PR
}

----

// we have gone through the playlist. if mStopAtEnd, stop the queue here
if (theNextFileIndex == 0 && THIS->mStopAtEnd)
{
    //THIS->mStopped = true; ///PR
    result = AudioQueueStop(inAQ, false);
    AssertNoError("Error stopping queue", end);
    return;
}

----

OSStatus Stop(Boolean inStopAtEnd)
{
  if (inStopAtEnd)
  {
    mStopAtEnd = true;
    returnnoErr;
  }
  else{
    //mStopped = true; ///PR
    returnAudioQueueStop(mQueue, true);
  }
}

----
Contributor

damian0815 commented Jul 4, 2012

hi @prossel, thanks for the issue report and patch.

in the near future ofxOpenALSoundPlayer is going to go away, to be replaced by ofOpenALSoundPlayer from the core (which is currently Linux-only). in the meantime i'll try and get this in.

@ghost ghost assigned damian0815 Jul 4, 2012

Owner

bilderbuchi commented Jun 20, 2013

Closed by #2127

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment