Playable state is a value that signals the possibility to play audio with current settings of the AudioDeviceManager for the moment.
The problem is that even if you can play audio right now, you can not be sure that you can play audio later. For instance if your app loses focus and antoher app is taking exclusive control of the sound card. With directsound that is possible, and as I said before even if you tell directsound that you want to play it can neglect you.
From msdn:
If the application does not have the input focus, IDirectSoundBuffer8::Restore might not succeed. For example, if the application with the input focus has the DSSCL_WRITEPRIMARY cooperative level, no other application will be able to restore its buffers. Similarly, an application with the DSSCL_WRITEPRIMARY cooperative level must have the input focus to restore its primary buffer.
I tried the following:
DWORD playCursor, writeCursor;
HRESULT hr = pOutputBuffer->GetCurrentPosition (&playCursor, &writeCursor);
if (hr != S_OK)
{
log (T("hr1 = ") + String ((int) hr));
hr = pOutputBuffer->Restore();
log (T("hr2 = ") + String ((int) hr));
hr = pOutputBuffer->GetCurrentPosition (&playCursor, &writeCursor);
log (T("hr3 = ") + String ((int) hr));
}
if (hr != S_OK)
{
logError (hr);
jassertfalse
return true;
}
I start my JUCE app, then I start a windows media center TV channel and I get following in the log file:
hr1 = -2005401450
hr2 = 0
hr3 = -2005401450
DS error at line 499 - Buffer lost
hr1 = -2005401450
hr2 = 0
hr3 = -2005401450
DS error at line 499 - Buffer lost
hr1 = -2005401450
hr2 = 0
hr3 = -2005401450
DS error at line 499 - Buffer lost
…
-2005401450 = 0x88780096 (DSERR_BUFFERLOST)
Really strange that hr2 is S_OK, maybe it is not valid to call GetCurrentPosition on a newly restored surface?
Do you want me to look into this issue?