AVProQuickTime

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;
        }
    }

}


评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值