有人可以提供帮助。当我通过单击按钮调用RequestDeviceAccess时,它总是返回false。
这是代码
public partial class MainPage:UserControl { private AudioCaptureDevice _audioDevice; private CaptureSource _captureSource; private AudioFormat _format; private MemoryAudioSink _sink;
public MainPage()
{
InitializeComponent();
_audioDevice = CaptureDeviceConfiguration.GetDefaultAudioCaptureDevice();
if (_audioDevice == null)
{
return;
}
_captureSource = new CaptureSource() { AudioCaptureDevice = _audioDevice };
_format = _captureSource.AudioCaptureDevice.SupportedFormats.FirstOrDefault(p => p.WaveFormat == WaveFormatType.Pcm && p.BitsPerSample == 16 && p.SamplesPerSecond == 8000 && p.Channels == 1);
_captureSource.AudioCaptureDevice.DesiredFormat = _format;
}
private bool EnsureAudioAccess()
{
return CaptureDeviceConfiguration.AllowedDeviceAccess || CaptureDeviceConfiguration.RequestDeviceAccess();
}
private void btnStartCapture_Click(object sender, RoutedEventArgs e)
{
if (!EnsureAudioAccess()) return;
_sink = new MemoryAudioSink();
_sink.CaptureSource = _captureSource;
_captureSource.Start();
this.media1.SetSource(_sink.BackingStream);
this.media1.Play();
}
}
答案 0 :(得分:1)
我遇到了同样的问题,并通过删除在以下验证之前设置的所有断点进行排序:
return CaptureDeviceConfiguration.AllowedDeviceAccess || CaptureDeviceConfiguration.RequestDeviceAccess();
尝试调用saveFileDialog.ShowDialog()方法时,我也遇到了类似的问题,并设置了断点。删除了断点和瞧。
希望它有所帮助!
答案 1 :(得分:1)
在调试模式下,它总是返回false。在Release上运行项目。 Ctrl + F5
答案 2 :(得分:0)
根据Silverlight.net网站,必须调用CaptureDeviceConfiguration()以响应用户启动的事件,例如点击按钮:
http://www.silverlight.net/learn/graphics/webcam-and-mic/webcams-(silverlight-quickstart)