Unity-Mobile Movie Texture视频插件的使用

Unity-Mobile Movie Texture视频插件的使用_第1张图片 Unity-Mobile Movie Texture视频插件的使用_第2张图片 Unity-Mobile Movie Texture视频插件的使用_第3张图片
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(MMT.MobileMovieTexture))]
public class VideoPlay : MonoBehaviour
{
    private MMT.MobileMovieTexture m_movieTexture;//视频播放插件
    private bool uislider;//视频更新进度判断条件
    private bool PassSpriteName;//暂停/继续视频按钮判断条件

    public UISprite PassSprite;//暂停按钮Sprite
    public UISprite StartSprite;//继续按钮Sprite
    public UISprite AgainStartSprite;//重新开始按钮Sprite

    public UISlider VideoPlan;//视频进度条
    public UILabel VideoName;//显示视频名称
    public string Video;//视频地址
    public GameObject button;//三角型滑动块
    public GameObject ButtonSlider;//视频进度条
    void Awake()
    {
        UIEventListener.Get(button).onPress = onButtonPressed;//三角型滑动块的按下抬起事件初始化
        UIEventListener.Get(ButtonSlider).onPress = onButtonSlider;//视频进度条的按下抬起事件初始化
        //视频播放插件的初始
        m_movieTexture = GetComponent();
        m_movieTexture.onFinished += OnFinished;
    }
    void Start()
    {
        PassSprite.enabled = true;//暂停按钮Sprite
        StartSprite.enabled = false;//继续按钮Sprite
        PassSpriteName = true;//重新开始按钮Sprite
        uislider = true;//视频更新进度判断条件
        m_movieTexture.Path = Video;//播放什么视频
    }
    /// 
    /// 视频播放完调用的方法
    /// 
    /// 
    void OnFinished(MMT.MobileMovieTexture sender)
    {
        PassSprite.enabled = false;
        StartSprite.enabled = false;
        AgainStartSprite.enabled = true;
    }
    // Update is called once per frame
    void Update()
    {
        VideoName.text = Video;
        if (uislider) { VideoSlider(); }
        else { m_movieTexture.playPosition = m_movieTexture.duration * VideoPlan.value; }

    }
    /// 
    /// 更型视频进度条
    /// 
    void VideoSlider()
    {
        VideoPlan.value = (float)m_movieTexture.playPosition / (float)m_movieTexture.duration;
    }
    /// 
    /// 开始按钮调用的方法
    /// 
    public void start()
    {
        m_movieTexture.Play();
        PassSprite.enabled = true;
        StartSprite.enabled = false;
        AgainStartSprite.enabled = false;
        PassSpriteName = true;
    }
    //停止方法
    //public void Stop()
    //{
    //    m_movieTexture.Stop();
    //}
    /// 
    /// 暂停或继续按钮调用的方法
    /// 
    public void pase()
    {
        if (PassSpriteName)
        {
            PassSpriteName = false;
            PassSprite.enabled = false;
            StartSprite.enabled = true;
        }
        else
        {
            PassSprite.enabled = true;
            StartSprite.enabled = false;
            PassSpriteName = true;
        }
        m_movieTexture.pause = !m_movieTexture.pause;//视频的暂停或者继续
    }
    /// 
    /// 三角型滑动块的按下和抬起
    /// 
    /// 
    /// 
    public void onButtonPressed(GameObject go, bool isDown)
    {
        if (uislider)
        {
            uislider = false;
        }
        else
        {
            uislider = true;
        }
    }
    /// 
    /// 视频进度条的按下和抬起
    /// 
    /// 
    /// 
    public void onButtonSlider(GameObject go, bool isDown)
    {
        if (uislider)
        {
            uislider = false;
        }
        else
        {
            uislider = true;
        }
    }
}

你可能感兴趣的:(unity)