internal static async Task RequestMediaAccessAsync(StreamingCaptureMode mode) { // Ensure that the UWP app was authorized to capture audio (cap:microphone) // or video (cap:webcam), otherwise the native plugin will fail. try { MediaCapture mediaAccessRequester = new MediaCapture(); var mediaSettings = new MediaCaptureInitializationSettings { AudioDeviceId = "", VideoDeviceId = "", StreamingCaptureMode = mode, PhotoCaptureSource = PhotoCaptureSource.VideoPreview }; await mediaAccessRequester.InitializeAsync(mediaSettings); } catch (UnauthorizedAccessException uae) { Logger.Log("Access to A/V denied, check app permissions: " + uae.Message); throw uae; } catch (Exception ex) { Logger.Log("Failed to initialize A/V with unknown exception: " + ex.Message); throw ex; } }
/// <summary> /// Handles changes to the StreamingCaptureMode property. /// </summary> /// <param name="d"> /// The <see cref="DependencyObject"/> on which /// the property has changed value. /// </param> /// <param name="e"> /// Event data that is issued by any event that /// tracks changes to the effective value of this property. /// </param> private static void OnStreamingCaptureModeChanged( DependencyObject d, DependencyPropertyChangedEventArgs e) { var target = (CameraCaptureControl)d; StreamingCaptureMode oldStreamingCaptureMode = (StreamingCaptureMode)e.OldValue; StreamingCaptureMode newStreamingCaptureMode = target.StreamingCaptureMode; target.OnStreamingCaptureModeChanged(oldStreamingCaptureMode, newStreamingCaptureMode); }
private MediaCaptureInitializationSettings CreateSettings(StreamingCaptureMode mode) { return(new MediaCaptureInitializationSettings { SharingMode = MediaCaptureSharingMode.SharedReadOnly, StreamingCaptureMode = mode, MemoryPreference = MediaCaptureMemoryPreference.Auto, }); }
public GeneralMediaCapturer(MediaFrameSourceGroup sourceGroup, StreamingCaptureMode mode) { var settings = CreateSettings(mode); settings.SourceGroup = sourceGroup; mediaCapture = new MediaCapture(); mediaCapture.InitializeAsync(settings).AsTask().Wait(); InitReader(); }
public GeneralMediaCapturer(DeviceInformation device, StreamingCaptureMode mode) { var settings = CreateSettings(mode); if (mode == StreamingCaptureMode.Video) { settings.VideoDeviceId = device.Id; } else { settings.AudioDeviceId = device.Id; } mediaCapture = new MediaCapture(); mediaCapture.InitializeAsync(settings).AsTask().Wait(); InitReader(); }
internal static Task <bool> RequestAccessAsync(StreamingCaptureMode mode) { // Note that the UWP UI thread and the main Unity app thread are always different. // https://docs.unity3d.com/Manual/windowsstore-appcallbacks.html Debug.Assert(!UnityEngine.WSA.Application.RunningOnUIThread()); var permissionTcs = new TaskCompletionSource <bool>(); UnityEngine.WSA.Application.InvokeOnUIThread(() => { // Request UWP access to audio or video capture. The OS may show some popup dialog to the // user to request permission. This will succeed only if the user grants permission. try { var mediaAccessRequester = new MediaCapture(); var mediaSettings = new MediaCaptureInitializationSettings(); mediaSettings.AudioDeviceId = ""; mediaSettings.VideoDeviceId = ""; mediaSettings.StreamingCaptureMode = mode; mediaSettings.PhotoCaptureSource = PhotoCaptureSource.VideoPreview; mediaSettings.SharingMode = MediaCaptureSharingMode.SharedReadOnly; // for MRC and lower res camera mediaAccessRequester.InitializeAsync(mediaSettings).AsTask().ContinueWith(task => { if (task.Exception != null) { Debug.LogError($"Media access failure: {task.Exception.InnerException.Message}."); permissionTcs.SetResult(false); } else { permissionTcs.SetResult(true); } }); } catch (Exception ex) { // Log an error and prevent activation Debug.LogError($"Media access failure: {ex.Message}."); permissionTcs.SetResult(false); } }, waitUntilDone: false); return(permissionTcs.Task); }
/// <summary> /// Provides derived classes an opportunity to handle changes /// to the StreamingCaptureMode property. /// </summary> /// <param name="oldStreamingCaptureMode">The old StreamingCaptureMode value</param> /// <param name="newStreamingCaptureMode">The new StreamingCaptureMode value</param> protected virtual void OnStreamingCaptureModeChanged( StreamingCaptureMode oldStreamingCaptureMode, StreamingCaptureMode newStreamingCaptureMode) { }