Quantcast
Channel: GameDev.net
Viewing all articles
Browse latest Browse all 16874

XAudio2_7 don't raise onCriticalError when headphones unplugged and app may hangs

$
0
0
#include <iostream>
#include <wrl.h>
#include <mfapi.h>
#include <XAudio2.h>
#pragma comment(lib, "mfplat.lib")

struct MyXAudio2EngineCallback : public IXAudio2EngineCallback {
    void STDMETHODCALLTYPE OnProcessingPassEnd() override {}
    void STDMETHODCALLTYPE OnProcessingPassStart() override {}
    void STDMETHODCALLTYPE OnCriticalError(HRESULT Error) {
        std::cerr << "OnCriticalError finished\n";
    }
};

class AudioEngine {
public:
    AudioEngine() {
        auto mDLL = LoadLibraryEx(L"XAudio2_7.DLL", nullptr, 0x00000800 /* LOAD_LIBRARY_SEARCH_SYSTEM32 */);
        if (!mDLL) {
            std::cerr << "Error: XAudio 2.7 not installed on system (June 2010)\n";
        }
        auto hr = MFStartup(MF_VERSION);
        if (FAILED(hr)) {
            std::cerr << "Error: Unable to start the Windows Media Foundation!\n";
        }

        engineCallback = std::make_unique<MyXAudio2EngineCallback>();
        createEngine();
    }

    bool recreateEngine() {
        destroyEngine();
        return createEngine();
    }

private:
    bool createEngine() {
        auto …

Viewing all articles
Browse latest Browse all 16874

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>