using UnityEngine;
using System.Collections;
public class Test : MonoBehaviour
{
public GameObject movieObj;
AVProQuickTimeGUIDisplay gui;
// Use this for initialization
void Start()
{
movieObj = new GameObject("Movie");
AVProQuickTimeMovie movie = movieObj.AddComponent<AVProQuickTimeMovie>();
movie._folder = Application.streamingAssetsPath + "/";
movie._filename = "test.mp4.bin";
movie._loop = true;
movie._loadOnStart = true;
movie._playOnStart = true;
gui = movieObj.AddComponent<AVProQuickTimeGUIDisplay>();
gui._movie = movie;
gui._scaleMode = ScaleMode.ScaleToFit;
gui._width = 0.5f;
gui._height =0.5f;
gui._fullScreen = false;
gui._alphaBlend = false;
gui._depth = 5;
gui._color = new Color(0.8f, 0.8f, 0.8f, 1.0f);
}
// Update is called once per frame
void Update()
{
}
void OnGUI()
{
DrawVideoControls(new Rect(0, 0, 200, 200), gui);
}
private void DrawVideoControls(Rect area, AVProQuickTimeGUIDisplay movieGUI)
{
AVProQuickTimeMovie movie = movieGUI._movie;
AVProQuickTime player = movie.MovieInstance;
if (player == null)
return;
// 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();
}
}
Plugins文件夹拖到Project面板下, 下面的界面用了NGUI,视频放在了新建的StreamingAssets文件夹下。
切换视频可以这样:
void OnGUI()
{
if (Input.GetMouseButtonDown(0))
{
movie._filename = "grey-480x256.mp4.bin";
movie.LoadMovie();
movie.Play();
}
}
using UnityEngine;
using System.Collections;
public class MovieController : MonoBehaviour
{
public string movieFileName;
public GameObject smallmoviePlane;
AVProQuickTimeMovie movie;
AVProQuickTimeMaterialApply atma;
AVProQuickTime moviePlayer;
public UISlider leftSlider;
public UISlider rightSlider;
bool flag = true;
void Awake()
{
gameObject.AddComponent<AVProQuickTimeManager>();
movie = gameObject.AddComponent<AVProQuickTimeMovie>();
movie._folder = Application.streamingAssetsPath + "/";
movie._filename = movieFileName;
movie._loop = true;
movie._loadOnStart = true;
movie._playOnStart = true;
atma = gameObject.AddComponent<AVProQuickTimeMaterialApply>();
atma._material = smallmoviePlane.renderer.material;
atma._movie = movie;
}
// Use this for initialization
void Start()
{
UIEventListener.Get(leftSlider.thumb.gameObject).onPress += DragPress;
}
// Update is called once per frame
void Update()
{
moviePlayer = movie.MovieInstance;
if (flag)
{
leftSlider.value = moviePlayer.PositionSeconds / moviePlayer.DurationSeconds;
}
else
{
moviePlayer.PositionSeconds = moviePlayer.DurationSeconds * leftSlider.value;
}
movie._volume = rightSlider.value;
}
void DragPress(GameObject go, bool b)
{
if (b)
{
flag = false;
}
else
{
flag = true;
}
}
}