title: How to play audio buffer from IMFSourceReader using Media Foundation
body: <p>I've just spent the all day trying to find a solution regarding that problem, let me explain a bit:</p>
  
  <p>I am developing a video tool on Windows using Visual 2013, Qt, OpenGL and Media Foundation in c++.
  I've got a IMFSourceReader that is grabbing video frame that I treat and display using openGL inside a QWindow.</p>
  
  <p>Now I want to play the audio stream of the video file.
  I know how to grab a audio sample (using the same source reader).
  I also know how to enumerate all my audio devices:
  
  
  <pre><code>IMMDeviceEnumerator *pEnum = NULL;      // Audio device enumerator.
  IMMDeviceCollection *pDevices = NULL;   // Audio device collection.
  IMMDevice *pDevice = NULL;              // An audio device.
  IMFAttributes *pAttributes = NULL;      // Attribute store.
  IMFMediaSink *pSink = NULL;             // Streaming audio renderer (SAR)
  
  LPWSTR wstrID = NULL;                   // Device ID.
  
  // Create the device enumerator.
  hr = CoCreateInstance(
      __uuidof(MMDeviceEnumerator),
      NULL,
      CLSCTX_ALL,
      __uuidof(IMMDeviceEnumerator),
      (void**)&amp;pEnum
      );
  
  // Enumerate the rendering devices.
  if (SUCCEEDED(hr))
  {
      hr = pEnum-&gt;EnumAudioEndpoints(eRender, DEVICE_STATE_ACTIVE, &amp;pDevices);
  }
  
  // Get ID of the first device in the list.
  if (SUCCEEDED(hr))
  {
      hr = pDevices-&gt;Item(0, &amp;pDevice);
  }
  
  if (SUCCEEDED(hr))
  {
      hr = pDevice-&gt;GetId(&amp;wstrID);
  }
  
  // Create an attribute store and set the device ID attribute.
  if (SUCCEEDED(hr))
  {
      hr = MFCreateAttributes(&amp;pAttributes, 2);
  }
  
  if (SUCCEEDED(hr))
  {
      hr = pAttributes-&gt;SetString(
          MF_AUDIO_RENDERER_ATTRIBUTE_ENDPOINT_ID,
          wstrID
          );
  }
  
  // Create the audio renderer.
  if (SUCCEEDED(hr))
  {
      hr = MFCreateAudioRenderer(pAttributes, &amp;pSink);
  }
  
  SAFE_RELEASE(pEnum);
  SAFE_RELEASE(pDevices);
  SAFE_RELEASE(pDevice);
  SAFE_RELEASE(pAttributes);
  CoTaskMemFree(wstrID);
  }
  </code></pre>
  
  <p>I think I have to go with <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa369729(v=vs.85).aspx" rel="nofollow">a Streaming Audio Renderer</a> but that is all. I can't find any thing on the web, I even went on the 11th page of a Google search...</p>
  
  <p>You are my only hope SO...</p>