Exemplo n.º 1
0
        public override IEnumerator Load()
        {
            //start the loading operation
            _mediaPlayer.Load(_mediaPlayer.videoPath);
            Events.OnClipLoadingStarted();

            //while the video is loading you can't play it
            while (_mediaPlayer.IsLoading())
            {
                VideoLoaded = false;
                yield return(null);
            }

            VideoLoaded = true;
            Events.OnClipLoadingFinished();
            yield return(null);
        }
        // Update is called once per frame
        void Update()
        {
            if (player == null)
            {
                return;
            }
            switch (mode)
            {
            case Mode.SEEK:
                if (_slider && !_isPointerDown)
                {
                    try {
                        _slider.value = Mathf.Clamp01(System.Convert.ToSingle(player.GetCurrentPosition(true)));
                    }
                    catch (Exception)
                    {
                        Debug.Log("ERROR Converting double to float:");
                    }

                    //Debug.Log("GetCurrentPosition:" + _slider.value);
                }
                if (_slider && _isPointerDown)
                {
                    _UpdateDrag();
                }
                break;

            case Mode.VOLUME:
                if (_slider && !_isPointerDown)
                {
                    _slider.value = player.volume;
                }
                if (_slider && _isPointerDown)
                {
                    _UpdateDrag();
                }
                break;

            case Mode.PLAY:
                if (_button)
                {
                    if (player.IsPlaying())
                    {
                        // _colorBlock.normalColor = _colorBlock.highlightedColor = colors[(int)mode];
                        _colorBlock.normalColor      = colors[(int)mode];
                        _colorBlock.highlightedColor = colors[(int)mode];
                    }
                    else
                    {
                        _colorBlock.normalColor = _colorBlock.highlightedColor = Color.white;
                    }
                    _button.colors = _colorBlock;
                }
                break;

            case Mode.PAUSE:
                if (_button)
                {
                    if (player.IsPaused())
                    {
                        _colorBlock.normalColor = _colorBlock.highlightedColor = colors[(int)mode];
                    }
                    else
                    {
                        _colorBlock.normalColor = _colorBlock.highlightedColor = Color.white;
                    }
                    _button.colors = _colorBlock;
                }
                break;

            case Mode.LOAD:
                if (_button)
                {
                    if (player.IsLoading())
                    {
                        _colorBlock.normalColor = _colorBlock.highlightedColor = colors[(int)mode];
                    }
                    else
                    {
                        _colorBlock.normalColor = _colorBlock.highlightedColor = Color.white;
                    }
                    _button.colors = _colorBlock;
                }
                break;

            case Mode.AUTOPLAY:
                _toggle.isOn = player.autoPlay;
                break;

            case Mode.LOOP:
                _toggle.isOn = player.looping;
                break;

            case Mode.TEXTURE:
                if (_rawImage)
                {
                    _texture      = (Texture)player.GetVideoTexture();
                    _isNewTexture = _rawImage.texture != _texture;
                    if (_texture != null)
                    {
                    }
                    if (_isNewTexture)
                    {
                        //Bug with uvrect on ios :
                        #if (UNITY_IOS && !UNITY_EDITOR) && UNITY_5_4_OR_NEWER
                        int w = 16;
                        int h = 16;

                        while (w < _texture.width)
                        {
                            w = w * 2;
                        }
                        while (h < _texture.height)
                        {
                            h = h * 2;
                        }

                        Rect uvr = _rawImage.uvRect;
                        uvr.width        = w / (float)_texture.width;
                        uvr.height       = (h / (float)_texture.height) * -1;
                        uvr.y            = uvr.height * -1;
                        _rawImage.uvRect = uvr;
                        #endif
                    }

                    _rawImage.texture = _texture;
                    _rawImage.SetAllDirty();    //!!!!
                }

                break;

            case Mode.PLAYBACKRATE:
                if (_slider && !_isPointerDown)
                {
                    _slider.value = player.rate;
                }
                if (_slider && _isPointerDown)
                {
                    _UpdateDrag();
                }
                break;

            case Mode.TIME:
                //_Update();
                if (OnUpdateTime != null)
                {
                    OnUpdateTime(player.GetCurrentPosition(true), player.GetDuration());
                }
                break;

            case Mode.PATH:
                if (OnUpdate != null)
                {
                    OnUpdate();
                }
                break;
            }


            if (mode == Mode.PATH)
            {
                return;
            }

            //Deselect the current GUI element to display the right color state
            if (_eventSystem)
            {
                if (_eventSystem.currentSelectedGameObject == gameObject)
                {
                    //Debug.Log("RESET");
                    _eventSystem.SetSelectedGameObject(null);
                }
            }
        }