I'm trying to capture my webcam and system audio using Expression Encoder, the webcam works fine but the system audio is just silent.
I followed the tutorial here: CodeProject Expression Encoder Tutorial but it isn't working for me properly.
When I list the audio devices, "Speakers...", "Microphone..." and "Headphones..." are listed (as they are in Playback Devices in the system tray) but if I try and record from either Speakers or Headphones I get nothing (I get the mic audio fine if I select that one).
Here is the code I'm using:
job = new LiveJob();
LiveDeviceSource lds = job.AddDeviceSource(ledv[0], leda[1]);
FileArchivePublishFormat fileOut = new FileArchivePublishFormat();
fileOut.OutputFileName = string.Format("C:\\Users\\user1\\Desktop\\testvideo-{0:yyyyMMdd_hhmmss}.wmv", DateTime.Now);
job.PublishFormats.Add(fileOut);
lds.PreviewWindow = new PreviewWindow(new System.Runtime.InteropServices.HandleRef(panel1, panel1.Handle));
job.StartEncoding();
job.ActivateSource(lds);
Does anyone have any idea why it doesn't record system audio? Are there any other settings I need to mess with before it should work?
Thanks for your time.
EDIT:
I decided to print out job.CurrentAudioVolume when it is encoding to see if this ever changed but it always just sits at 0. If I change the audio device to the microphone, this value goes up when there is sound (as expected). So it definitely looks like the SDK is unable to record my system audio (either from Speakers or Headphones).
Okay I sorted it out with a bit of help from a colleague.
Basically Headphones/Speakers etc. are just output devices and so you need to install a loopback driver as an input device.
There's a free one on Sourceforge/Github that works great. Just select it as the audio device.
There is one small problem, I've got a "record"/"stop" button that calls job.StopEncoding(); but with the loopback audio driver chosen StopEncoding() hangs the Window, I guess because the loopback driver doesn't get stopped properly, but if you call job.RemoveDeviceSource(deviceSource); after you call StopEncoding() and then re-add before the next StartEncoding() it works fine.