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);
        }
Example #3
0
 void OnDestroy()
 {
     SetUpWatchHistory();
     MLScreens.Stop();
     if (_mediaPlayer)
     {
         _mediaPlayer.OnMediaError    -= HandleError;
         _mediaPlayer.OnVideoPrepared -= HandleVideoPrepared;
     }
 }
Example #4
0
        /// <summary>
        /// Create or Update the watch history for this application
        /// </summary>
        private void SetUpWatchHistory()
        {
            MLResult result;
            List <MLScreensWatchHistoryEntry> history = MLScreens.GetAllEntries();

            if (history.Count == 0)
            {
                // We have no history and need to create some.
                var entry = new MLScreensWatchHistoryEntry()
                {
                    // Value should be ignored
                    Id = long.MaxValue,

                    Title              = "NASA",
                    Subtitle           = "Cold Atom Laboratory",
                    PlaybackPositionMs = (uint)_mediaPlayer.GetElapsedTimeMs(),
                    PlaybackDurationMs = (uint)_mediaPlayer.GetDurationMs(),
                };

                if (GetNewThumbnail())
                {
                    result = MLScreens.Add(ref entry, _thumbnail);
                }
                else
                {
                    result = MLScreens.Add(ref entry, _defaultThumbnail);
                }
            }
            else
            {
                // We have existing History just update it with latest times and thumbnail
                var entry = history[0];
                entry.PlaybackPositionMs = (uint)_mediaPlayer.GetElapsedTimeMs();
                entry.PlaybackDurationMs = (uint)_mediaPlayer.GetDurationMs();
                if (GetNewThumbnail())
                {
                    result = MLScreens.UpdateWatchHistory(entry, _thumbnail);
                }
                else
                {
                    result = MLScreens.UpdateWatchHistory(entry, _defaultThumbnail);
                }
            }

            if (!result.IsOk)
            {
                Debug.LogErrorFormat("Error: ScreensExample MLScreens.UpdateWatchHistory failed. Reason {0}.", result);
            }
        }
Example #5
0
        /// <summary>
        /// Update the screen position if it has moved
        /// </summary>
        private void SetScreenLocation()
        {
            if (PositionChanged())
            {
                _launchedScreenInfo.Position = _launchedScreen.transform.position;
                _launchedScreenInfo.Rotation = _launchedScreen.transform.rotation;

                MLResult result = MLScreens.UpdateScreenInfo(_launchedScreenInfo);
                if (!result.IsOk)
                {
                    Debug.LogErrorFormat("Error: ScreensExample failed for id {0}. Reason {1}.", _launchedScreenInfo.Id, result);
                    return;
                }
            }
        }