开发者

Silverlight 4 RequestDeviceAccess() Always returns null. No dialog

开发者 https://www.devze.com 2023-03-02 05:29 出处:网络
Can some one help.When I call RequestDeviceAccess 开发者_运维百科by clicking the button it always returns false.

Can some one help. When I call RequestDeviceAccess 开发者_运维百科by clicking the button it always returns false.

Here is the code

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();
    }

}


I came across the same problem and sorted it out by removing all breakpoints set before the following verification:

return CaptureDeviceConfiguration.AllowedDeviceAccess || CaptureDeviceConfiguration.RequestDeviceAccess();

I also had a similar problem when trying to call the saveFileDialog.ShowDialog() method with a breakpoint set on it. Removed the breakpoint and voila.

Hope it helps!


In debug mode it always return false. Run project on Release. Ctrl + F5


According to the Silverlight.net website, calls to CaptureDeviceConfiguration() must be made in response to a user-initiated event, such as a button click:

http://www.silverlight.net/learn/graphics/webcam-and-mic/webcams-(silverlight-quickstart)

0

精彩评论

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