示例#1
0
        // Update is called once per frame
        void Update()
        {
            _multipleMedia = sphere.GetComponent <MultiplePlayerControl>();
            _player        = _multipleMedia.Player;
            _gatedClips    = GetComponents <GatedClip>();
            _playableClips = GetComponents <PlayableClip>();
            _previewMode   = GetComponent <PreviewMode>();
            Array.Sort(_playableClips);
            this.transform.position = Camera.main.transform.position;

            currentTime        = _multipleMedia.GetCurrentTime();
            CurrentVisibleView = GetVisibleView();
            if (_multipleMedia.IsPaused())
            {
                float relativeTime = currentTime - _playableClips[_currentClipIndex].startTime;
                Debug.Log("Current frame: " + (int)(currentTime * _multipleMedia.Player.Info.GetVideoFrameRate()) + ". Current view is " + CurrentVisibleView + ". Current clip: " + GetCurrentClipIndex());
                Debug.Log("Relative frame: " + (int)(relativeTime * _multipleMedia.Player.Info.GetVideoFrameRate()));
            }

            currentTime = _multipleMedia.GetCurrentTime();

            if (initialized)  // Need in case the first clip does not start at t = 0s of the raw video.
            {
                Debug.Log("Is playing? " + _multipleMedia.IsPlaying());
                _multipleMedia.Seek(_playableClips[0].startTime);
                if (Mathf.Abs(_player.Control.GetCurrentTimeMs() / 1000f - _playableClips[0].startTime) < GetVideoFps())
                {
                    initialized = false;
                }
                Debug.Log("Initialized. Current time: " + Mathf.Abs(_player.Control.GetCurrentTimeMs()) / 1000f + ", Initialized? " + initialized.ToString());
                return;
            }

            // If there are no playable clips, stop.
            if (_playableClips.Length == 0 || _currentClipIndex < 0 || _currentClipIndex >= _playableClips.Length)
            {
                this.SetPlayMode(false);
                this.PauseVideo();
                return;
            }

            if (!_multipleMedia.SyncMediaPlayers() && _multipleMedia.isTransitioning)
            {
                Debug.Log("Not in sync DESPITE FORCEWAIT");
                if (_multipleMedia.Player.Control.IsSeeking())
                {
                    playMode = false;
                }
                else if (_multipleMedia.OtherPlayer.Control.IsSeeking())
                {
                    playMode = false;
                }
            }

            currentTime = _multipleMedia.GetCurrentTime();

            if (playMode)
            {
                this.PlayVideo();
            }
            else
            {
                this.PauseVideo();
            }
            this.SetupEquirectTexture();

            // Storing equirect texture into PreviewMode component, which is read by VideoEditorWindow.
            if (_player.TextureProducer != null)
            {
                if (_previewMode.equirectTexture != null)
                {
                    MediaPlayer equirectPlayer = _multipleMedia.GetEquirectPlayer();
                    if (equirectPlayer != null)
                    {
                        _previewMode.equirectTexture = (Texture2D)equirectPlayer.TextureProducer.GetTexture();
                    }
                }
            }

            if (currentTime < _playableClips[_currentClipIndex].startTime - 5)
            {
                Debug.Log("Current time " + currentTime + " is less than start time of clip index " + _currentClipIndex + ": " + _playableClips[_currentClipIndex] + ". Skipping ahead...");
                _multipleMedia.Seek(_playableClips[_currentClipIndex].startTime);
                return;
            }

            _previewMode.SetCurrentClip(_playableClips[_currentClipIndex].clipIndex);
            int previousClipIndex = _currentClipIndex;
            int currentFrame      = (int)(currentTime * _multipleMedia.Player.Info.GetVideoFrameRate());

            // Check whether playable clip is gated clip.
            GatedClip gc = _playableClips[_currentClipIndex] as GatedClip;

            if (gc != null)
            {
                // This clip is a gated clip.
                if ((_player.Control.IsPlaying() || _multipleMedia.IsPaused()) && gc.checkSalient(currentTime, _multipleMedia, this))
                {
                    currentTime = _multipleMedia.GetCurrentTime();
                    Debug.Log("Current time: " + currentTime + ". Current face: " + GetVisibleView() + ". Passed gated clip " + gc + ". Moving from index: " + _currentClipIndex);

                    if (_multipleMedia.isTransitioning)
                    {
                        Debug.Log("Finishing in-progress transition.");
                        _multipleMedia.FinishTransition();
                        Debug.Log("Multiple media is transition? " + _multipleMedia.isTransitioning);
                    }
                    else
                    {
                        Debug.Log("No in-progress transition");
                    }
                    _playableClips = sphere.GetComponents <PlayableClip>();
                    Array.Sort(_playableClips);

                    _currentClipIndex++;
                    _multipleMedia.expectedCurrentFrame = 0;
                    _multipleMedia.expectedNextFrame    = 1;
                    while (_currentClipIndex < _playableClips.Length && !_playableClips[_currentClipIndex].enabled)
                    {
                        _currentClipIndex++;
                        _multipleMedia.expectedCurrentFrame = 0;
                        _multipleMedia.expectedNextFrame    = 1;
                    }
                    Debug.Log("Next clip index: " + _currentClipIndex);
                    if (_currentClipIndex >= 0 && _currentClipIndex < _playableClips.Length)
                    {
                        Debug.Log(_playableClips[_currentClipIndex].ToString());
                    }
                    _multipleMedia.UpdateAudio();
                }
            }
            else  // Not a gated clip.
            {
                if (_player.Control.IsPlaying() && _playableClips[_currentClipIndex].checkSalient(currentTime, _multipleMedia, this))
                {
                    _playableClips = sphere.GetComponents <PlayableClip>();
                    Array.Sort(_playableClips);
                    Debug.Log("Current time: " + currentTime + ". Finished clip " + _playableClips[_currentClipIndex] + ". Moving from index: " + _currentClipIndex);
                    _currentClipIndex++;
                    _multipleMedia.expectedCurrentFrame = 0;
                    _multipleMedia.expectedNextFrame    = 1;

                    while (_currentClipIndex < _playableClips.Length && !_playableClips[_currentClipIndex].enabled)
                    {
                        _currentClipIndex++;
                        _multipleMedia.expectedCurrentFrame = 0;
                        _multipleMedia.expectedNextFrame    = 1;
                    }
                    Debug.Log("Next clip index: " + _currentClipIndex);
                    _multipleMedia.UpdateAudio();
                }
            }

            if (_currentClipIndex >= _playableClips.Length)
            {
                _currentClipIndex = -1;
                Debug.Log("End of all clips.");
                SetPlayMode(false);
                return;
            }

            if (previousClipIndex != _currentClipIndex && Mathf.Abs(_playableClips[_currentClipIndex].startTime - _playableClips[previousClipIndex].endTime) > 0.5f)
            {
                Debug.Log("Jumping to beginning of next clip index: " + _currentClipIndex + ". " + _playableClips[_currentClipIndex].ToString());
                _multipleMedia.Seek(_playableClips[_currentClipIndex].startTime);
            }
        }