简体   繁体   中英

Changing audio renderer endpoint while playing

I'm writing an audio player using Microsoft Media Foundation. I wonder is it possible to change the playback device without re-creating the session?

IMFActivate *m_p_sink_activate;
...
m_p_sink_activate->SetString(MF_AUDIO_RENDERER_ATTRIBUTE_ENDPOINT_ID, name_device);

This doesn't take effect if the audio is already being played.

Btw, the media player provided by Microsoft.Windows.SDK.Contracts (Windows.Media.Playback.MediaPlayer) does it perfectly. When I change m_mediaPlayer.AudioDevice, the audio stream is redirected to the assigned device immediately. So I wonder if this is also possible for MSMF.

So far I have a way could do this job,

  1. Create a new topology which cloned from previous one.
  2. Create new audio renderer using MFCreateAudioRendererActivate and using set string with the new audio endpoint ID add it to a topologynode;
  3. Add the new node to new topology;
  4. Using IMFMediaSession::SetTopology() do set new topology to play.

You could refer to MS sample TopoEdit for detail.

One side effect is that each time SetTopology cause huge memory growth.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM