PDK Sound Service Instance -> IsPlaying() Function

SDK supports Prepar3D’s philosophy of an open development architecture and encourages third parties to bring new innovations with improved add-ons and training content.
Post Reply
flyboy7798
Posts: 37
Joined: Thu Jul 20, 2017 7:15 pm

PDK Sound Service Instance -> IsPlaying() Function

Post by flyboy7798 »

The other forum topic related to this problem was marked resolved: https://prepar3d.com/forum/viewtopic.ph ... 1&t=131939 I have updated to 4.5 and now the warning sound (that was working) will play once and then the next time IsPlaying() is called it returns E_FAIL. The same code that was working in 4.4 just fine, now seems defective in 4.5. Any ideas why this behavior is happening?
Clifton Crane
Lockheed Martin
Posts: 1207
Joined: Tue Sep 25, 2012 2:34 pm

Re: PDK Sound Service Instance -> IsPlaying() Function

Post by Clifton Crane »

Hi flyboy7798,

Does the first time calling IsPlaying() return S_FALSE? Is it only the second time IsPlaying() returns E_FAIL? Could you provide a code snippet showing how you are listening to IsPlaying() and then calling Play()?

Thanks.
Clifton Crane
Prepar3D® Software Engineer Sr.
flyboy7798
Posts: 37
Joined: Thu Jul 20, 2017 7:15 pm

Re: PDK Sound Service Instance -> IsPlaying() Function

Post by flyboy7798 »

Clifton, thanks for the rapid response. To answer the first question, the debug log shows this sequence:

pPdkSoundInstance->Play() IN playSound() RETURNED S_OK
pPdkSoundInstance->IsPlaying() IN stopSound() RETURNED E_FAIL
pPdkSoundInstance->IsPlaying() IN playSound() RETURNED E_FAIL
pPdkSoundInstance->IsPlaying() IN stopSound() RETURNED E_FAIL

Here are the functions for play and stop play (simplfied):

Code: Select all

void AudibleSystem::playSound()
{
    HRESULT hr = pPdkSoundInstance->IsPlaying();

    if (hr == S_OK)
    {
        //Do nothing since the sound is playing       
    }
    else if ((hr == S_FALSE) || (hr == 0x887800aa))
    {
        hr = pPdkSoundInstance->Play();

        if (hr == S_OK)
        {
            LOGGER->Log("...");
        }
        else if (hr == E_FAIL)
        {
            LOGGER->Log("...");
        }
        else
        {
            LOGGER->Log("...");
        }
    }
    else if (hr == E_FAIL)
    {
        LOGGER->Log("...");
    }
}

void AudibleSystem::stopSound()
{
    HRESULT hr = pPdkSoundInstance->IsPlaying();

    if (hr == S_OK)
    {
        hr = pPdkSoundInstance->Stop();

        if (hr == S_OK)
        {
            //Do nothing
        }
        else if (hr == E_FAIL)
        {
            LOGGER->Log("...");
        }
    }
    else if (hr == S_FALSE)
    {
        //LOGGER->Log("...");
    }
    else if (hr == E_FAIL)
    {
        LOGGER->Log("...");
    }
}
Clifton Crane
Lockheed Martin
Posts: 1207
Joined: Tue Sep 25, 2012 2:34 pm

Re: PDK Sound Service Instance -> IsPlaying() Function

Post by Clifton Crane »

Hello,

I am not consistently seeing IsPlaying() return E_FAIL, however I do see it return E_FAIL if I call Play() once and then change sound settings (such as changing playback device or changing volume for a specific category).

If I do not make any sound changes IsPlaying() continues to return S_FALSE when not playing. Is there any other code you could provide that demonstrates how your playSound() and stopSound() functions are being used?

Also, could you provide the CreateSoundInstance parameters you are using?

Thanks.
Clifton Crane
Prepar3D® Software Engineer Sr.
flyboy7798
Posts: 37
Joined: Thu Jul 20, 2017 7:15 pm

Re: PDK Sound Service Instance -> IsPlaying() Function

Post by flyboy7798 »

This code hasn't changed since it worked in v4.4. I simplified the code in the earlier post. Here's a section of code which gets called at 18hz:

Code: Select all

if (!override_gear_warning)
   playLandingGearWarningSound();
else if (override_gear_warning)
   stopLandingGearWarningSound();

The larger context of that snippet is specific to the flight manuals requirement to have a gear warning sound when certain conditions exist. There are other places and other sounds that get called through the PDK from other objects. But this is representative of one of those And here's the instance creation loc:

Code: Select all

pPdkSoundService->CreateSoundInstance(pszSoundFileName, P3D::SOUND_GROUP::SOUND_GROUP_COCKPIT, P3D::VIEW_POINT::VIEW_POINT_INTERIOR, TRUE, FALSE, FALSE, (void **)&pPdkGearWarningSoundInstance);
Post Reply