public void Update()
    {
        if (_moviePlayer != null)
        {
            _volume = Mathf.Clamp01(_volume);
            if (_allowAudio)
            {
                if (_volume != _moviePlayer.Volume)
                {
                    _moviePlayer.Volume = _volume;
                }
                if (_audioBalance != _moviePlayer.AudioBalance)
                {
                    _moviePlayer.AudioBalance = _audioBalance;
                }
            }

            if (_loop != _moviePlayer.Loop)
            {
                _moviePlayer.Loop = _loop;
            }

            _moviePlayer.Update(false);

            // When the movie finishes playing, send a message so it can be handled
            if (!_moviePlayer.Loop && _moviePlayer.IsPlaying && _moviePlayer.IsFinishedPlaying)
            {
                _moviePlayer.Pause();
                this.SendMessage("MovieFinished", this, SendMessageOptions.DontRequireReceiver);
            }
        }
    }
Ejemplo n.º 2
0
 public void Pause()
 {
     if (_moviePlayer != null)
     {
         _moviePlayer.Pause();
     }
 }
Ejemplo n.º 3
0
    private void DrawVideoControls(Rect area, AVProWindowsMediaGUIDisplay movieGUI)
    {
        AVProWindowsMediaMovie movie  = movieGUI._movie;
        AVProWindowsMedia      player = movie.MovieInstance;

        if (player == null)
        {
            return;
        }

        // Close button
        if (GUI.Button(new Rect(area.x + (area.width - 32), area.y, 32, 32), "X"))
        {
            _removeMovie = movieGUI;
        }

        // Duplicate button
        if (GUI.Button(new Rect(area.x + (area.width - 64), area.y, 32, 32), "+"))
        {
            Add(movie._folder, movie._filename);
        }

        // Video properties
        GUILayout.BeginArea(new Rect(area.x, area.y, area.width / 2, area.height / 2));
        GUILayout.Label(player.Width + "x" + player.Height + "/" + player.FrameRate.ToString("F2") + "hz");
        GUILayout.EndArea();

        GUILayout.BeginArea(new Rect(area.x, area.y + (area.height - 32), area.width, 32));
        GUILayout.BeginHorizontal();
        float position    = player.PositionSeconds;
        float newPosition = GUILayout.HorizontalSlider(position, 0.0f, player.DurationSeconds, GUILayout.ExpandWidth(true));

        if (position != newPosition)
        {
            player.PositionSeconds = newPosition;
        }
        if (player.IsPlaying)
        {
            if (GUILayout.Button("Pause", GUILayout.ExpandWidth(false)))
            {
                player.Pause();
            }
        }
        else
        {
            if (GUILayout.Button("Play", GUILayout.ExpandWidth(false)))
            {
                player.Play();
            }
        }
        GUILayout.EndHorizontal();
        GUILayout.EndArea();
    }
    public void ControlWindow(int id)
    {
        if (_movie == null)
        {
            return;
        }

        GUILayout.Space(16f);

        GUILayout.BeginVertical();

        GUILayout.BeginHorizontal();
        GUILayout.Label("Folder: ", GUILayout.Width(100));
        _movie._folder = GUILayout.TextField(_movie._folder, 192);
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        GUILayout.Label("File: ", GUILayout.Width(100));
        _movie._filename = GUILayout.TextField(_movie._filename, 128, GUILayout.Width(440));
        if (GUILayout.Button("Load File", GUILayout.Width(90)))
        {
            if (!_playFromMemory)
            {
                _movie.LoadMovie(true);
            }
            else
            {
                LoadFileToMemory(_movie._folder, _movie._filename);
            }
        }
        GUILayout.EndHorizontal();


        if (_display != null)
        {
            GUILayout.BeginHorizontal();
            GUILayout.Space(100f);

            /*if (_display._alphaBlend)
             *      _display._alphaBlend = GUILayout.Toggle(_display._alphaBlend, "Rendering with Transparency");
             * else
             * _display._alphaBlend = GUILayout.Toggle(_display._alphaBlend, "Rendering without Transparency");*/

            if (_display._alphaBlend != GUILayout.Toggle(_display._alphaBlend, "Render with Transparency"))
            {
                _display._alphaBlend = !_display._alphaBlend;
                if (_display._alphaBlend)
                {
                    _movie._colourFormat = AVProWindowsMediaMovie.ColourFormat.RGBA32;
                }
                else
                {
                    _movie._colourFormat = AVProWindowsMediaMovie.ColourFormat.YCbCr_HD;
                }

                if (!_playFromMemory)
                {
                    _movie.LoadMovie(true);
                }
                else
                {
                    LoadFileToMemory(_movie._folder, _movie._filename);
                }
            }



            if (_playFromMemory != GUILayout.Toggle(_playFromMemory, "Play from Memory"))
            {
                _playFromMemory = !_playFromMemory;
                if (_movie.MovieInstance != null)
                {
                    if (!_playFromMemory)
                    {
                        _movie.LoadMovie(true);
                    }
                    else
                    {
                        LoadFileToMemory(_movie._folder, _movie._filename);
                    }
                }
            }

            GUILayout.EndHorizontal();
        }

        AVProWindowsMedia moviePlayer = _movie.MovieInstance;

        if (moviePlayer != null)
        {
            GUILayout.BeginHorizontal();
            GUILayout.Label("Info:", GUILayout.Width(100f));
            GUILayout.Label(moviePlayer.Width + "x" + moviePlayer.Height + " @ " + moviePlayer.FrameRate.ToString("F2") + " FPS");
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Volume ", GUILayout.Width(100));
            float volume    = _movie._volume;
            float newVolume = GUILayout.HorizontalSlider(volume, 0.0f, 1.0f, GUILayout.Width(200));
            if (volume != newVolume)
            {
                _movie._volume = newVolume;
            }
            GUILayout.Label(_movie._volume.ToString("F1"));
            GUILayout.EndHorizontal();


            GUILayout.BeginHorizontal();
            GUILayout.Label("Balance ", GUILayout.Width(100));
            float balance    = _movie._audioBalance;
            float newBalance = GUILayout.HorizontalSlider(balance, -1.0f, 1.0f, GUILayout.Width(200));
            if (balance != newBalance)
            {
                _movie._audioBalance = newBalance;
            }
            GUILayout.Label(moviePlayer.AudioBalance.ToString("F1"));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Audio Delay", GUILayout.Width(100));
            int delay    = moviePlayer.AudioDelay;
            int newDelay = Mathf.FloorToInt(GUILayout.HorizontalSlider(delay, -1000.0f, 1000.0f, GUILayout.Width(200)));
            if (delay != newDelay)
            {
                moviePlayer.AudioDelay = newDelay;
            }
            float msPerFrame = 1000.0f / moviePlayer.FrameRate;
            int   frameDelay = Mathf.FloorToInt((float)newDelay / msPerFrame);
            GUILayout.Label(moviePlayer.AudioDelay.ToString() + "ms (" + frameDelay + " frames)");
            GUILayout.EndHorizontal();



            GUILayout.BeginHorizontal();
            GUILayout.Label("Time ", GUILayout.Width(100));
            float position    = moviePlayer.PositionSeconds;
            float newPosition = GUILayout.HorizontalSlider(position, 0.0f, moviePlayer.DurationSeconds, GUILayout.Width(200));
            if (position != newPosition)
            {
                moviePlayer.PositionSeconds = newPosition;
            }
            GUILayout.Label(moviePlayer.PositionSeconds.ToString("F2") + " / " + moviePlayer.DurationSeconds.ToString("F3") + "s");

            if (GUILayout.Button("Play"))
            {
                moviePlayer.Play();
            }
            if (GUILayout.Button("Pause"))
            {
                moviePlayer.Pause();
            }
            GUILayout.EndHorizontal();


            GUILayout.BeginHorizontal();
            GUILayout.Label("Frame", GUILayout.Width(100f));

            uint positionFrame = moviePlayer.PositionFrames;
            if (positionFrame != uint.MaxValue)
            {
                uint newPositionFrame = (uint)GUILayout.HorizontalSlider(positionFrame, 0.0f, (float)moviePlayer.LastFrame, GUILayout.Width(200));
                if (positionFrame != newPositionFrame)
                {
                    moviePlayer.PositionFrames = newPositionFrame;
                }

                GUILayout.Label(moviePlayer.PositionFrames.ToString() + " / " + moviePlayer.LastFrame.ToString());

                if (GUILayout.RepeatButton("<", GUILayout.Width(50)))
                {
                    if (moviePlayer.PositionFrames > 0)
                    {
                        moviePlayer.PositionFrames--;
                    }
                }
                if (GUILayout.RepeatButton(">", GUILayout.Width(50)))
                {
                    if (moviePlayer.PositionFrames < moviePlayer.LastFrame)
                    {
                        moviePlayer.PositionFrames++;
                    }
                }

                GUILayout.EndHorizontal();
            }



            GUILayout.BeginHorizontal();
            GUILayout.Label("Rate ", GUILayout.Width(100f));
            GUILayout.Label(moviePlayer.PlaybackRate.ToString("F2") + "x");
            if (GUILayout.Button("-", GUILayout.Width(50)))
            {
                moviePlayer.PlaybackRate = moviePlayer.PlaybackRate * 0.5f;
            }

            if (GUILayout.Button("+", GUILayout.Width(50)))
            {
                moviePlayer.PlaybackRate = moviePlayer.PlaybackRate * 2.0f;
            }
            GUILayout.EndHorizontal();
#if UNITY_EDITOR
            GUILayout.Label("Displaying at " + moviePlayer.DisplayFPS.ToString("F1") + " fps");
#endif
        }

        GUILayout.EndVertical();
    }
    public void ControlWindow(int id)
    {
        if (_movie == null)
        {
            return;
        }

        GUILayout.Space(16f);

        GUILayout.BeginVertical();

        GUILayout.BeginHorizontal();
        GUILayout.Label("Folder: ", GUILayout.Width(80));
        _movie._folder = GUILayout.TextField(_movie._folder, 192);
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        GUILayout.Label("File: ", GUILayout.Width(80));
        _movie._filename = GUILayout.TextField(_movie._filename, 128, GUILayout.Width(440));
        if (GUILayout.Button("Load File", GUILayout.Width(90)))
        {
            _movie.LoadMovie(true);
        }
        GUILayout.EndHorizontal();

        bool alphaBlend = _movie._colourFormat == AVProWindowsMediaMovie.ColourFormat.RGBA32;

        if (alphaBlend)
        {
            alphaBlend = GUILayout.Toggle(alphaBlend, "Render with Transparency (requires movie reload)");
        }
        else
        {
            alphaBlend = GUILayout.Toggle(alphaBlend, "Render without Transparency");
        }

        if (alphaBlend)
        {
            _movie._colourFormat = AVProWindowsMediaMovie.ColourFormat.RGBA32;
        }
        else
        {
            _movie._colourFormat = AVProWindowsMediaMovie.ColourFormat.YCbCr_HD;
        }


        AVProWindowsMedia moviePlayer = _movie.MovieInstance;

        if (moviePlayer != null)
        {
            GUILayout.BeginHorizontal();
            GUILayout.Label("Info:", GUILayout.Width(80f));
            GUILayout.Label(moviePlayer.Width + "x" + moviePlayer.Height + " @ " + moviePlayer.FrameRate.ToString("F2") + " FPS");
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Volume ", GUILayout.Width(80));
            float volume    = _movie._volume;
            float newVolume = GUILayout.HorizontalSlider(volume, 0.0f, 1.0f, GUILayout.Width(200));
            if (volume != newVolume)
            {
                _movie._volume = newVolume;
            }
            GUILayout.Label(_movie._volume.ToString("F1"));
            GUILayout.EndHorizontal();


            GUILayout.BeginHorizontal();
            GUILayout.Label("Balance ", GUILayout.Width(80));
            float balance    = moviePlayer.AudioBalance;
            float newBalance = GUILayout.HorizontalSlider(balance, -1.0f, 1.0f, GUILayout.Width(200));
            if (balance != newBalance)
            {
                moviePlayer.AudioBalance = newBalance;
            }
            GUILayout.Label(moviePlayer.AudioBalance.ToString("F1"));
            GUILayout.EndHorizontal();


            GUILayout.BeginHorizontal();
            GUILayout.Label("Time ", GUILayout.Width(80));
            float position    = moviePlayer.PositionSeconds;
            float newPosition = GUILayout.HorizontalSlider(position, 0.0f, moviePlayer.DurationSeconds, GUILayout.Width(200));
            if (position != newPosition)
            {
                moviePlayer.PositionSeconds = newPosition;
            }
            GUILayout.Label(moviePlayer.PositionSeconds.ToString("F1") + " / " + moviePlayer.DurationSeconds.ToString("F1") + "s");

            if (GUILayout.Button("Play"))
            {
                moviePlayer.Play();
            }
            if (GUILayout.Button("Pause"))
            {
                moviePlayer.Pause();
            }
            GUILayout.EndHorizontal();


            GUILayout.BeginHorizontal();
            GUILayout.Label("Frame", GUILayout.Width(80f));
            GUILayout.Label(moviePlayer.PositionFrames.ToString() + " / " + moviePlayer.DurationFrames.ToString());

            if (GUILayout.Button("<", GUILayout.Width(50)))
            {
                moviePlayer.Pause();
                if (moviePlayer.PositionFrames > 0)
                {
                    moviePlayer.PositionFrames--;
                }
            }
            if (GUILayout.Button(">", GUILayout.Width(50)))
            {
                moviePlayer.Pause();
                if (moviePlayer.PositionFrames < moviePlayer.DurationFrames)
                {
                    moviePlayer.PositionFrames++;
                }
            }

            GUILayout.EndHorizontal();



            GUILayout.BeginHorizontal();
            GUILayout.Label("Rate ", GUILayout.Width(80f));
            GUILayout.Label(moviePlayer.PlaybackRate.ToString("F2") + "x");
            if (GUILayout.Button("-", GUILayout.Width(50)))
            {
                moviePlayer.PlaybackRate = moviePlayer.PlaybackRate * 0.5f;
            }

            if (GUILayout.Button("+", GUILayout.Width(50)))
            {
                moviePlayer.PlaybackRate = moviePlayer.PlaybackRate * 2.0f;
            }
            GUILayout.EndHorizontal();
        }

        GUILayout.EndVertical();
    }