Example #1
0
        void Start()
        {
            MLResult result = MLInput.Start();

            if (!result.IsOk)
            {
                Debug.LogErrorFormat("Error: ScreensExample failed to start MLInput, disabling script. Reason {0}", result);
                enabled = false;
                return;
            }

            result = MLScreens.Start();
            if (!result.IsOk)
            {
                Debug.LogErrorFormat("Error: ScreensExample failed to start MLScreens, disabling script. Reason {0}", result);
                enabled = false;
                return;
            }

            if (MLScreens.GetLauncherScreenId() == -1)
            {
                Debug.LogError("Error: ScreensExample is unable to parse screen id from command line. " +
                               "Make sure app is launched from screens universe launcher, disabling script..");
                enabled = false;
                return;
            }

            if (!UpdateLaunchedScreen())
            {
                return;
            }

            if (!_mediaPlayer)
            {
                Debug.LogError("Error: ScreensExample no MLMediaPlayer Found");
                DisplayVideoError();
                return;
            }

            _mediaPlayer.OnMediaError    += HandleError;
            _mediaPlayer.OnVideoPrepared += HandleVideoPrepared;

            _mediaPlayer.VideoSource = _url;
            result = _mediaPlayer.PrepareVideo();
            if (!result.IsOk)
            {
                if (result.Code == MLResultCode.PrivilegeDenied)
                {
                    Instantiate(Resources.Load("PrivilegeDeniedError"));
                }
                DisplayVideoError();
                Debug.LogErrorFormat("Error: ScreensExample MLMediaPlayer PrepareVideo failed. Reason {0}", result);
            }

            EnableUI(false);
        }
Example #2
0
        /// <summary>
        /// Retrieve the launched screen information and update the visual GameObject.
        /// </summary>
        private bool UpdateLaunchedScreen()
        {
            List <MLScreensScreenInfo> info;

            MLResult result = MLScreens.GetScreensInfo(out info);

            if (!result.IsOk)
            {
                Debug.LogErrorFormat("Error: ScreensExample MLScreens.GetScreensInfo failed. Reason {0}.", result);
                return(false);
            }

            if (info.Count == 0)
            {
                _noScreensError.enabled = true;
                Debug.LogWarning("Warning: ScreensExample no screen information was located.");
                return(false);
            }

            // Obtain a list of the available screens and make sure a valid screen is returned.
            MLScreensScreenInfo[] screenInfo = info.Where(x => x.Id == (ulong)MLScreens.GetLauncherScreenId()).ToArray();
            if (screenInfo.Length > 0)
            {
                if (_launchedScreen == null)
                {
                    // Create the initial launched screen GameObject.
                    _launchedScreen = Instantiate(_screenOriginal, screenInfo[0].Position, screenInfo[0].Rotation, transform);
                    _launchedScreen.transform.localScale = Vector3.Scale(screenInfo[0].Dimensions, screenInfo[0].Scale);

                    _launchedScreenInfo = screenInfo[0];

                    _mediaPlayer         = _launchedScreen.GetComponentInChildren <MLMediaPlayer>();
                    _elapsedTime         = _launchedScreen.GetComponentInChildren <TextMesh>();
                    _placementComponenet = _launchedScreen.GetComponentInChildren <PlaceFromCamera>(true);
                }
                else
                {
                    // Assign the active screen info as the launched screen.
                    _launchedScreenInfo = screenInfo[0];

                    // Update the existing screen with the new launched values.
                    _launchedScreen.transform.position   = screenInfo[0].Position;
                    _launchedScreen.transform.rotation   = screenInfo[0].Rotation;
                    _launchedScreen.transform.localScale = Vector3.Scale(screenInfo[0].Dimensions, screenInfo[0].Scale);
                }
            }
            else
            {
                Debug.LogError("Error: ScreensExample was unable to located the launched screen information.");
                enabled = false;

                return(false);
            }

            return(true);
        }