Silverlight 4 Capture source is not stopped

2019-09-08 00:55发布

问题:

I am working on a Silverlight project to record the audio on a web page.

After I clicked the Pause button the code will always throw an exception:

Capture source is not stopped

If I put a break point on this line of code and wait there for 3-5 seconds then run the code, no exception will be threw.

    if (audioSink.CaptureSource.State == CaptureState.Started) (break point is on this line)

Here is the code

   private void Pause(object sender, RoutedEventArgs e)
    {
        //System.Threading.Thread.Sleep(TimeSpan.FromSeconds(5));
        if (audioSink.CaptureSource.State == CaptureState.Started)
        {
            audioSink.CaptureSource.Stop();

            this.btnPause.IsEnabled = false;
            this.btnRecord.IsEnabled = true;
            this.btnSave.IsEnabled = true;
        }
    }

   audioSink.CaptureSource.Stop(); (This is the line of code which throws the exception)

回答1:

Not sure if it might help:

While using video source I tend to use CaptureDeviceConfiguration.AllowDeviceAccess property in order to check whether I can manipulate the capture object.

You can obtain the access to the device by calling CaptureDeviceConfiguration.RequestDeviceAccess. You should be calling this method before calling the Start method of the capture. If you do this on the Start method, than you should already have the access and call the Stop method without having problems.