1

I am currently using the WPF MediaKit in an application I am working on. I am having an issue with audio. On some computers playback would not work at all. It was confusing because it seemed to work sometimes and not others. Then I noticed it was failing to open the media because of an audio issue. If there are no audio devices connected the cannot open the audio stream and fails completely. This is a problem, we can tell people they have to connect speakers for the application to function. Is there a way I can tell it to just ignore the audio if this happens and still play the video? Here is the error I am getting.

System.Runtime.InteropServices.COMException (0x80040256): Cannot play back the audio stream: no audio hardware is available, or the hardware is not responding.
   at DirectShowLib.DsError.ThrowExceptionForHR(Int32 hr)
   at WPFMediaKit.DirectShow.MediaPlayers.MediaPlayerBase.AddFilterByDevice(IGraphBuilder graphBuilder, DsDevice device)
   at WPFMediaKit.DirectShow.MediaPlayers.MediaPlayerBase.AddFilterByName(IGraphBuilder graphBuilder, Guid deviceCategory, String friendlyName)
   at WPFMediaKit.DirectShow.MediaPlayers.MediaUriPlayer.InsertAudioRenderer(String audioDeviceName)
   at WPFMediaKit.DirectShow.MediaPlayers.MediaUriPlayer.OpenSource()
xmedeko
  • 7,336
  • 6
  • 55
  • 85
thecaptain0220
  • 2,098
  • 5
  • 30
  • 51

1 Answers1

2

0x80040256 is VFW_E_NO_AUDIO_HARDWARE "Cannot play back the audio stream: no audio hardware is available, or the hardware is not responding." which means that the system does not have audio output device to play to.

WPFMediaKit however assumes you have some, and attempts to create audio renderer unconditionally. That is, you have to edit this in WPFMediaKit code to work it around.

Roman R.
  • 68,205
  • 6
  • 94
  • 158
  • Is there a way I could detect that there is no audio hardware and disable the audio renderer? – thecaptain0220 Jun 03 '14 at 14:12
  • `InsertAudioRenderer` there attempts to insert a filter by its name. It does not find it and fails. This is the detection you need. You just need to suppress the exception rather than pass it through. – Roman R. Jun 03 '14 at 14:14
  • That worked perfectly. Thanks. Is there a reason this is not the default behavior? I seems odd that simply not having speakers connected is cause to completely fail to load the media. – thecaptain0220 Jun 03 '14 at 17:51
  • Well that's a question for [Jeremiah Morill](http://stackoverflow.com/users/115854/jeremiah-morrill). My guess is that this is not on purpose and he just missed the scenario where video content is played back on system with no audio output.... – Roman R. Jun 03 '14 at 18:01
  • It's already fixed in the new [WPF-MediaKit](http://github.com/Sascha-L/WPF-MediaKit) – xmedeko Feb 07 '17 at 12:12