Пример #1
0
        /// <summary>
        /// Stop capturing video.
        /// </summary>
        public void EndCapture()
        {
            if (_isCapturing)
            {
                MLResult result = MLCamera.StopVideoCapture();
                if (result.IsOk)
                {
                    _isCapturing      = false;
                    _captureStartTime = 0;
                    OnVideoCaptureEnded.Invoke(_captureFilePath);
                    _captureFilePath = null;
                }
                else
                {
                    if (result.Code == MLResultCode.PrivilegeDenied)
                    {
                        Instantiate(Resources.Load("PrivilegeDeniedError"));
                    }

                    Debug.LogErrorFormat("Error: VideoCaptureExample failed to end video capture. Error Code: {0}", MLCamera.GetErrorCode().ToString());
                }
            }
            else
            {
                Debug.LogError("Error: VideoCaptureExample failed to end video capture because the camera is not recording.");
            }
        }
Пример #2
0
    void processVideo()
    {
        if (videostate == VideoState.VIDEO_READY)
        {
            videostate = VideoState.VIDEO_STARTED;
            MLog("Starting video");
            MLCamera.StartVideoCapture(filepath);
            MLog("Started video");
            count = 0;
        }

        count++;

        if (count > 240 && videostate == VideoState.VIDEO_STARTED)
        {
            videostate = VideoState.VIDEO_ENDED;
            MLog("Stopping video");
            MLCamera.StopVideoCapture();
            MLog("Stopped video");
        }

        if (videostate == VideoState.VIDEO_ENDED)
        {
            sendVideo();
        }
    }
Пример #3
0
        /// <summary>
        /// Stop capturing video.
        /// </summary>
        public void EndCapture(bool captureCanceled = false)
        {
            if (_isCapturing)
            {
                #if PLATFORM_LUMIN
                MLResult result = MLCamera.StopVideoCapture();
                if (result.IsOk)
                {
                    // If we did not record long enough make sure our path is marked as invalid to avoid trying to load invalid file.
                    if (Time.time - _captureStartTime < _minRecordingTime)
                    {
                        _captureFilePath = null;
                    }

                    if (!captureCanceled)
                    {
                        if (_rawVideoCaptureMode)
                        {
                            OnRawVideoCaptureEnded.Invoke();
                        }
                        else
                        {
                            OnVideoCaptureEnded.Invoke(_captureFilePath);
                        }
                    }

                    _isCapturing      = false;
                    _captureStartTime = 0;
                    _captureFilePath  = null;
                }
                else
                {
                    Debug.LogErrorFormat("Error: VideoCaptureExample failed to end video capture. Error Code: {0}", MLCamera.GetErrorCode().ToString());
                }
                #endif
            }
            else
            {
                Debug.LogError("Error: VideoCaptureExample failed to end video capture because the camera is not recording.");
            }
        }
 /// <summary>
 /// Stop capturing video.
 /// </summary>
 public void EndCapture()
 {
     if (_isCapturing)
     {
         MLResult result = MLCamera.StopVideoCapture();
         if (result.IsOk)
         {
             _isCapturing      = false;
             _captureStartTime = 0;
             OnVideoCaptureEnded?.Invoke();
         }
         else
         {
             CheckPrivilegeDenied(result);
             Debug.LogErrorFormat("Error: RawVideoCaptureExample failed to end raw video capture. Error Code: {0}", MLCamera.GetErrorCode().ToString());
         }
     }
     else
     {
         Debug.LogError("Error: RawVideoCaptureExample failed to end raw video capture because the camera is not capturing.");
     }
 }
 /// <summary>
 /// Stop capturing video.
 /// </summary>
 public void EndCapture()
 {
     if (_isCapturing)
     {
         MLResult result = MLCamera.StopVideoCapture();
         if (result.IsOk)
         {
             _isCapturing      = false;
             _captureStartTime = 0;
             OnVideoCaptureEnded.Invoke(_captureFilePath);
             _captureFilePath = null;
         }
         else
         {
             Debug.LogErrorFormat("Failure: Could not end video capture. Error Code: {0}",
                                  MLCamera.GetErrorCode().ToString());
         }
     }
     else
     {
         Debug.LogError("Failure: Could not EndCapture() because the camera is not recording.");
     }
 }
Пример #6
0
        async UniTask DoStart()
        {
            // Get a WiFi privilege
            await MLUtils.RequestPrivilege(MLPrivilegeId.LocalAreaNetwork);

            _credentials.ClearStorage();
            _client = new TWClient(_credentials, _credentials);

            _onApplicationResume = new Subject <Unit>();

            ClearLines();
            AppendLine("You may use a dummy Twitter account for this demo.");
            AppendLine("Press Trigger button to start...");

            // Wait for a trigger by user
            await MLUtils.OnTriggerUpAsObservable().ToUniTask(useFirstValue: true);

            ClearLines();
            AppendLine("You'll be prompted to open Helio shortly...");

            // Initiate 3-legged authentication.
            // Callback URL must be your app's URI configured in the manifest,
            // also must be registered in your Twitter app's "Callback URLs" list.
            // See https://forum.magicleap.com/hc/en-us/community/posts/360042601671
            // and https://developer.twitter.com/en/docs/basics/apps/guides/callback-urls
            string authUrl = await _client.GetUserAuthenticationUrl(_credentials.CallbackUrl);

            // Open the URL on Helio and let user log in to Twitter
            MLDispatcher.TryOpenAppropriateApplication(authUrl).ThrowIfFail();

            ClearLines();
            AppendLine("Waiting for a redirect from Helio...");
            AppendLine("(if you'd like to retry, please exit all apps)");

            /* Magic Leap's dispatcher is generally immature and
             * you'll find MANY causes of failure here
             * but for this demo I just let user initialize everything in such cases
             * for the simplicity of this code...
             */

            // Wait for getting redirected from Helio
            await _onApplicationResume.ToUniTask(useFirstValue : true);

            // Authorize using the redirect URL sent from Helio
            var redirectUrl = Environment.GetCommandLineArgs()[0];
            await _client.AuthorizeUser(redirectUrl);

            ClearLines();
            AppendLine("Authorized with your Twitter account!");
            AppendLine("Press Trigger button to tweet on your account");
            AppendLine("Please end this demo if your account is public)");

            // Wait for a trigger by user
            await MLUtils.OnTriggerUpAsObservable().ToUniTask(useFirstValue: true);

            // Tweet a sample text (note that all characters survive URL encoding)
            await _client.UpdateStatus("Tweeting from #MagicLeap using MLTwitter https://github.com/ryo0ka/MLTwitter");

            // Get the authorized user's latest status (which is the tweet above)
            var user = await _client.VerifyCredentials();

            // Present the tweet to user
            await _statusView.Show(user);

            ClearLines();
            AppendLine("Check out your new tweet!");
            AppendLine("Press Trigger button to move on to the next demo...");

            // Wait for a trigger by user
            await MLUtils.OnTriggerUpAsObservable().ToUniTask(useFirstValue: true);

            // Hide the twitter ui
            await _statusView.Hide();

            ClearLines();
            AppendLine("Press Trigger button to start video capture & upload...");
            AppendLine("(Tweet will contain a video captured from now.");
            AppendLine("Please end this demo if your privacy is concerned)");

            // Wait for a trigger by user
            await MLUtils.OnTriggerUpAsObservable().ToUniTask(useFirstValue: true);

            // Make a file path for the video
            string videoFilePath = Path.Combine(Application.temporaryCachePath, "video.mp4");

            // Update privileges just in case
            await MLUtils.RequestPrivilege(MLPrivilegeId.LocalAreaNetwork);

            await MLUtils.RequestPrivilege(MLPrivilegeId.CameraCapture);

            await MLUtils.RequestPrivilege(MLPrivilegeId.AudioCaptureMic);

            // Start video recording
            MLCamera.Start().ThrowIfFail();
            MLCamera.Connect().ThrowIfFail();
            MLCamera.StartVideoCapture(videoFilePath);

            ClearLines();
            AppendLine("Press Trigger button to STOP video capture and upload it on Twitter...");

            // Wait for a trigger by user
            await MLUtils.OnTriggerUpAsObservable().ToUniTask(useFirstValue: true);

            // Stop video recording
            MLCamera.StopVideoCapture().ThrowIfFail();

            ClearLines();
            AppendLine("Stoped video capture. Encoding...");

            // Wait until encoding is over
            await MLUtils.OnCaptureCompletedAsObservable().ToUniTask(useFirstValue: true);

            // Stop capture service
            MLCamera.Disconnect().ThrowIfFail();
            MLCamera.Stop();

            ClearLines();
            AppendLine("Finished encoding. Uploading to Twitter...");

            // Read the video file
            byte[] video = File.ReadAllBytes(videoFilePath);

            // Upload the video to Twitter (this is just a media upload; not a tweet)
            string videoMediaId = await _client.UploadVideo(video, (upload, encode) =>
            {
                ClearLines();
                AppendLine($"Uploading: {upload * 100:0}% done, encoding: {encode * 100:0}% done...");
            });

            // Tweet the video
            await _client.UpdateStatus("Uploading a video capture from #MagicLeap using MLTwitter", videoMediaId);

            // Present the tweet to user
            user = await _client.VerifyCredentials();

            await _statusView.Show(user);

            ClearLines();
            AppendLine("Check out your new tweet!");
            AppendLine("");
            AppendLine("You've reached the end of this demo.");
            AppendLine("Press Trigger button to exit the app...");

            // Wait for a trigger by user
            await MLUtils.OnTriggerUpAsObservable().ToUniTask(useFirstValue: true);

            // Cool animation
            await _statusView.Hide();

            Application.Quit();
        }