Wasapi player: unregister system volume change callback on player destroy. Fixes crash when changing Windows volume after switching streams

Wasapi player: unregister system volume change callback on player destroy. Fixes crash when changing Windows volume after switching streams
This commit is contained in:
Stijn Van der Borght 2021-03-20 10:04:45 +00:00 committed by badaix
parent ea1236feef
commit af621acf1c
2 changed files with 3 additions and 2 deletions

View file

@ -83,6 +83,7 @@ WASAPIPlayer::WASAPIPlayer(boost::asio::io_context& io_context, const ClientSett
WASAPIPlayer::~WASAPIPlayer()
{
audioEndpointListener_->UnregisterControlChangeNotify(&audioEndpointVolumeCallback_);
WASAPIPlayer::stop();
}
@ -250,10 +251,9 @@ void WASAPIPlayer::worker()
hr = control->RegisterAudioSessionNotification(audioEventListener_);
CHECK_HR(hr);
AudioEndpointVolumeCallback audioEndpointVolumeCallback;
hr = device->Activate(IID_IAudioEndpointVolume, CLSCTX_ALL, NULL, (void**)&audioEndpointListener_);
audioEndpointListener_->RegisterControlChangeNotify((IAudioEndpointVolumeCallback*)&audioEndpointVolumeCallback);
audioEndpointListener_->RegisterControlChangeNotify((IAudioEndpointVolumeCallback*)&audioEndpointVolumeCallback_);
// Get the device period
REFERENCE_TIME hnsRequestedDuration = REFTIMES_PER_SEC;