0

我正在开发一个 Silverlight 项目,以在网页上录制音频。

单击暂停按钮后,代码将始终抛出异常:

捕获源未停止

如果我在这行代码上放一个断点并在那里等待 3-5 秒然后运行代码,不会抛出异常。

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

这是代码

   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)
4

1 回答 1

0

不确定它是否有帮助:

在使用视频源时,我倾向于使用CaptureDeviceConfiguration.AllowDeviceAccess属性来检查我是否可以操纵捕获对象。

您可以通过调用CaptureDeviceConfiguration.RequestDeviceAccess获得对设备的访问权限。您应该在调用捕获的 Start 方法之前调用此方法。如果您在 Start 方法上执行此操作,那么您应该已经有权访问并调用 Stop 方法而不会出现问题。

于 2012-09-10T07:45:17.317 回答