My application should be playing 24/7. However it sometimes can occur that a sound device is not available for a short time by mistake (e.g. because the cable of an USB device has a bad contact or has been pulled by mistake.)
In the application, there are one or more mixers, each with a number of streams with sync-points, splitters, sub-mixers...
When I detect the device has stopped playing and has become available again, I would like to reinitialize the device and continue playing (without having to rebuild the mixers, which would require a huge architectural change...)
The code to accomplish this looks something like this:
if (Bass.BASS_ChannelIsActive(hMixer) != BASSActive.BASS_ACTIVE_PLAYING)
{
Bass.BASS_SetDevice(2); // Set context first
Bass.BASS_ChannelStop(hMixer);
Bass.BASS_Free();
Bass.BASS_Init(2, 44100, BASSInit.BASS_DEVICE_SPEAKERS, hDSWindow);
int result = Bass.BASS_ChannelPlay(hMixer, false);
if (!result)
{
error = Bass.BASS_ErrorGetCode(); // BASS_ERROR_HANDLE !!!
}
}
However when trying to play the mixer again, I get an invalid handle error.
Is there a way to work around this?