Ejemplo n.º 1
0
        protected override async void Start()
        {
            base.Start();

#if !UNITY_STANDALONE_WIN && !UNITY_EDITOR
            // Request camera permissions
            if (!await MediaDeviceQuery.RequestPermissions <CameraDevice>())
            {
                Debug.LogError("User did not grant camera permissions");
                return;
            }
#endif

            // Load global camera benchmark settings.
            int width, height, framerate;
            NatDeviceWithOpenCVForUnityExample.CameraConfiguration(out width, out height, out framerate);
            // Create camera source
            cameraSource = new NatDeviceCamSource(width, height, framerate, useFrontCamera);
            if (cameraSource.activeCamera == null)
            {
                cameraSource = new NatDeviceCamSource(width, height, framerate, !useFrontCamera);
            }
            await cameraSource.StartRunning(OnStart, OnFrame);

            fpsMonitor = GetComponent <FpsMonitor>();
            if (fpsMonitor != null)
            {
                fpsMonitor.Add("Name", "NatDeviceCamPreviewOnlyExample");
                fpsMonitor.Add("onFrameFPS", onFrameFPS.ToString("F1"));
                fpsMonitor.Add("drawFPS", drawFPS.ToString("F1"));
                fpsMonitor.Add("width", "");
                fpsMonitor.Add("height", "");
                fpsMonitor.Add("orientation", "");
            }
        }
Ejemplo n.º 2
0
        async void Start()
        {
            // Request mic permissions
            if (!await MediaDeviceQuery.RequestPermissions <AudioDevice>())
            {
                Debug.LogError("User did not grant microphone permissions");
                return;
            }
            // Create a media device query for audio devices
            var deviceQuery = new MediaDeviceQuery(MediaDeviceQuery.Criteria.AudioDevice);

            // Get the device
            device = deviceQuery.currentDevice as AudioDevice;
            Debug.Log($"{device}");
        }
Ejemplo n.º 3
0
        async void Start()
        {
            // Request camera permissions
            if (!await MediaDeviceQuery.RequestPermissions <CameraDevice>())
            {
                Debug.LogError("User did not grant camera permissions");
                return;
            }
            // Create a device query for device cameras
            // Use `GenericCameraDevice` so we also capture WebCamTexture cameras
            query = new MediaDeviceQuery(Criteria.GenericCameraDevice);
            // Start camera preview
            var device         = query.currentDevice as ICameraDevice;
            var previewTexture = await device.StartRunning();

            Debug.Log($"Started camera preview with resolution {previewTexture.width}x{previewTexture.height}");
            // Display preview texture
            previewPanel.texture            = previewTexture;
            previewAspectFitter.aspectRatio = previewTexture.width / (float)previewTexture.height;
            // Set UI state
            switchIcon.color = query.devices.Length > 1 ? Color.white : Color.gray;
            flashIcon.color  = device is CameraDevice cameraDevice && cameraDevice.flashSupported ? Color.white : Color.gray;
        }