我正在研究Silverlight项目,以将音频记录在网页上.
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:
捕获源未停止
如果我在这行代码上放置一个断点并在那里等待3-5秒,然后运行代码,则不会抛出异常.
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)这是代码
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) 推荐答案不确定是否有帮助:
在使用视频源时,我倾向于使用 CaptureDeviceConfiguration.AllowDeviceAccess 属性,以检查是否可以操纵捕获对象.
While using video source I tend to use CaptureDeviceConfiguration.AllowDeviceAccess property in order to check whether I can manipulate the capture object.
您可以通过调用 CaptureDeviceConfiguration.RequestDeviceAccess .在调用捕获的Start方法之前,应该先调用此方法.如果在Start方法上执行此操作,则应该已经可以访问并调用Stop方法而不会出现问题.
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.
更多推荐
Silverlight 4 Capture源未停止
发布评论