public void Update() { _volume = Mathf.Clamp01(_volume); _audioBalance = Mathf.Clamp(_audioBalance, -1.0f, 1.0f); if (_moviePlayer != null) { if (_volume != _moviePlayer.Volume) { _moviePlayer.Volume = _volume; } if (_audioBalance != _moviePlayer.AudioBalance) { _moviePlayer.AudioBalance = _audioBalance; } if (_loop != _moviePlayer.Loop) { _moviePlayer.Loop = _loop; } if (!_moviePlayer.IsPlaying) { /*if (_loadFirstFrame) * { * if (_moviePlayer.PlayState == AVProQuickTime.PlaybackState.Loaded) * { * _moviePlayer.Frame = 0; * _loadFirstFrame = false; * } * }*/ if (_playOnStart) { // Auto play the movie on startup if ((int)_moviePlayer.PlayState >= (int)AVProQuickTime.PlaybackState.Loaded && _moviePlayer.LoadedSeconds > 0f) { _moviePlayer.Play(); _playOnStart = false; } } } _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); } } }
private void DrawVideoControls(Rect area, AVProQuickTimeGUIDisplay movieGUI) { AVProQuickTimeMovie movie = movieGUI._movie; AVProQuickTime 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(); }
private 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(350)); if (GUILayout.Button("Load File", GUILayout.Width(90))) { _movie._source = AVProQuickTimePlugin.MovieSource.LocalFile; _movie.LoadMovie(); } if (GUILayout.Button("Load URL", GUILayout.Width(90))) { _movie._source = AVProQuickTimePlugin.MovieSource.URL; _movie.LoadMovie(); } #if !UNITY_WEBPLAYER if (GUILayout.Button("Load Memory", GUILayout.Width(110))) { _movie._source = AVProQuickTimePlugin.MovieSource.Memory; string fullPath = System.IO.Path.Combine(_movie._folder, _movie._filename); if (System.IO.File.Exists(fullPath)) { _movie._movieData = System.IO.File.ReadAllBytes(fullPath); _movie.LoadMovie(); } } #endif GUILayout.EndHorizontal(); AVProQuickTime moviePlayer = _movie.MovieInstance; if (moviePlayer != null) { GUILayout.BeginHorizontal(); GUILayout.Label("Loaded ", GUILayout.Width(80)); GUILayout.HorizontalSlider(moviePlayer.LoadedSeconds, 0.0f, moviePlayer.DurationSeconds, GUILayout.Width(200)); if (moviePlayer.DurationSeconds > 0f) { GUILayout.Label(((moviePlayer.LoadedSeconds * 100f) / moviePlayer.DurationSeconds) + "%"); } else { GUILayout.Label("0%"); } GUILayout.EndHorizontal(); if (moviePlayer.LoadedSeconds > 0f) { GUILayout.Label("Resolution: " + moviePlayer.Width + "x" + moviePlayer.Height + " @ " + moviePlayer.FrameRate.ToString("F2") + "hz"); 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("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 " + moviePlayer.Frame.ToString() + " / " + moviePlayer.FrameCount.ToString()); if (GUILayout.Button("<", GUILayout.Width(50))) { if (moviePlayer.Frame > 0) { moviePlayer.Frame--; } } if (GUILayout.Button(">", GUILayout.Width(50))) { moviePlayer.Frame++; } GUILayout.EndHorizontal(); if (!moviePlayer.IsPaused) { GUILayout.BeginHorizontal(); GUILayout.Label("Rate: " + moviePlayer.PlaybackRate.ToString("F2") + "x"); if (GUILayout.Button("Reverse", GUILayout.Width(72))) { moviePlayer.PlaybackRate = -moviePlayer.PlaybackRate; } if (GUILayout.Button("-", GUILayout.Width(50))) { moviePlayer.PlaybackRate = moviePlayer.PlaybackRate * 0.5f; } if (GUILayout.Button("+", GUILayout.Width(50))) { moviePlayer.PlaybackRate = moviePlayer.PlaybackRate * 2.0f; } if (GUILayout.Button("Reset", GUILayout.Width(50))) { moviePlayer.PlaybackRate = 1.0f; } GUILayout.EndHorizontal(); } } } GUILayout.EndVertical(); }
private void ControlWindow(int id) { if (_movie == null) { return; } GUILayout.Space(16f); GUILayout.BeginVertical(); _movie._useStreamingAssetsPath = GUILayout.Toggle(_movie._useStreamingAssetsPath, "Use Streaming Assets Folder"); 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(350)); if (GUILayout.Button("Load File", GUILayout.Width(90))) { _movie._source = AVProQuickTimePlugin.MovieSource.LocalFile; _movie.LoadMovie(); } if (GUILayout.Button("Load URL", GUILayout.Width(90))) { _movie._source = AVProQuickTimePlugin.MovieSource.URL; _movie.LoadMovie(); } #if !UNITY_WEBPLAYER if (GUILayout.Button("Load Memory", GUILayout.Width(110))) { _movie._source = AVProQuickTimePlugin.MovieSource.Memory; string fullPath = System.IO.Path.Combine(_movie._folder, _movie._filename); if (System.IO.File.Exists(fullPath)) { _movie._movieData = System.IO.File.ReadAllBytes(fullPath); _movie.LoadMovie(); _movie._movieData = null; } System.GC.Collect(); System.GC.WaitForPendingFinalizers(); System.GC.Collect(); Debug.Log("GC: " + System.GC.GetTotalMemory(false)); } #endif GUILayout.EndHorizontal(); AVProQuickTime moviePlayer = _movie.MovieInstance; if (moviePlayer != null) { GUILayout.BeginHorizontal(); GUILayout.Label("Loaded ", GUILayout.Width(80)); GUILayout.HorizontalSlider(moviePlayer.LoadedSeconds, 0.0f, moviePlayer.DurationSeconds, GUILayout.Width(200)); if (moviePlayer.DurationSeconds > 0f) { GUILayout.Label(((moviePlayer.LoadedSeconds * 100f) / moviePlayer.DurationSeconds) + "%"); } else { GUILayout.Label("0%"); } GUILayout.EndHorizontal(); if (moviePlayer.LoadedSeconds > 0f || AVProQuickTimePlugin.IsMoviePlayable(moviePlayer.Handle)) { GUILayout.Label("Resolution: " + moviePlayer.Width + "x" + moviePlayer.Height + " @ " + moviePlayer.FrameRate.ToString("F2") + "hz"); 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("Alpha", GUILayout.Width(80)); _display._color.a = GUILayout.HorizontalSlider(_display._color.a, 0.0f, 1.0f, GUILayout.Width(200)); GUILayout.Label(_display._color.a.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; //moviePlayer.Play(); //moviePlayer.Update(true); } GUILayout.Label(moviePlayer.PositionSeconds.ToString("F2") + " / " + moviePlayer.DurationSeconds.ToString("F2") + "s"); if (GUILayout.Button("Play")) { moviePlayer.Play(); } if (GUILayout.Button("Pause")) { moviePlayer.Pause(); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Frame " + moviePlayer.Frame.ToString() + " / " + moviePlayer.FrameCount.ToString()); if (GUILayout.Button("<", GUILayout.Width(50))) { AVProQuickTimePlugin.SeekToPreviousFrame(moviePlayer.Handle); } if (GUILayout.Button(">", GUILayout.Width(50))) { AVProQuickTimePlugin.SeekToNextFrame(moviePlayer.Handle); } GUILayout.EndHorizontal(); if (!moviePlayer.IsPaused) { GUILayout.BeginHorizontal(); GUILayout.Label("Rate: " + moviePlayer.PlaybackRate.ToString("F2") + "x"); if (GUILayout.Button("Reverse", GUILayout.Width(72))) { moviePlayer.PlaybackRate = -moviePlayer.PlaybackRate; } if (GUILayout.Button("-", GUILayout.Width(50))) { moviePlayer.PlaybackRate = moviePlayer.PlaybackRate * 0.5f; } if (GUILayout.Button("+", GUILayout.Width(50))) { moviePlayer.PlaybackRate = moviePlayer.PlaybackRate * 2.0f; } if (GUILayout.Button("Reset", GUILayout.Width(50))) { moviePlayer.PlaybackRate = 1.0f; } GUILayout.EndHorizontal(); } } } GUILayout.EndVertical(); }