开发者

Capturing audio using Silverlight

开发者 https://www.devze.com 2023-02-21 00:39 出处:网络
I have some AudioSink which is assigned to some CaptureSource. CaptureSource captureSource = new CaptureSource() {

I have some AudioSink which is assigned to some CaptureSource.

CaptureSource captureSource = new CaptureSource() {
    VideoCaptureDevice = null,
    AudioCaptureDevice = CaptureDeviceConfiguration.GetDefaultAudioCaptureDevice()
};
SampleAudioSink audioSink = new SampleAudioSink() {
    CaptureSource = captureSource
};
captureSource.Start();

The AudioSink implementation simply logs the called function to see that it works properly. However, the OnSamples method stops being called after 37 samples.

  • OnCaptureStarted
  • OnFormatChange
  • OnSamples (1)
  • OnSamples (2)
  • OnSamples (3)
  • [...]
  • OnSamples (35)
  • OnSamples (36)
  • OnSamples (37)

OnCaptureStopped is never called; the CaptureSource should continuously call this function. The CaptureSource also does 开发者_Go百科not invoke the CaptureFailed event.

What could produce this strange behaviour and what attempts could I take to fix it?

I have uploaded a complete source code which produces the problem to Pastebin


The problem was that the garbage collector deleted the AudioSink after 18 seconds...
Adding the AudioSink as a class member solved the problem.

[...]
TextBox log;
SampleAudioSink audioSink; // to prevent garbage collector from collection
private void Application_Startup (object sender, StartupEventArgs e) {
    [...]
}
[...]
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号