Unity视频插件AVPro Video的事件管理

AVPro Video的事件管理,本文基于AVPro Video1.5.12。

Unity视频插件AVPro Video的事件管理_第1张图片

1. 事件注册方式:

void OnMediaPlayerEvent(MediaPlayer mp,MediaPlayerEvent.EventType et,ErrorCode errorCode)
    {
        switch (et)
        {
            case MediaPlayerEvent.EventType.Started:
                print("startedEvent开始事件触发");
                OnMediaPlayerStarted(mp);
                break;
            case MediaPlayerEvent.EventType.FinishedPlaying:
                print("finishedEvent结束事件触发");
                OnMediaPlayerFinished(mp);
                break;
        }
    }

OnMediaPlayerStarted(mp)视频播放开始事件触发后的执行方法OnMediaPlayerFinished(mp)视频播放开始事件触发后的执行方法

2. 全代码如下:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using RenderHeads.Media.AVProVideo;


public class AVPevent : MonoBehaviour {

    public MediaPlayer mediaplayer;
	void Start () {
        mediaplayer.Events.AddListener(OnMediaPlayerEvent);
        SetMovie("/game2/start/piantou.mp4");
	}
    void SetMovie(string mp4Str)//gamex + "/start/piantou.mp4"
    {
        mediaplayer.OpenVideoFromFile(MediaPlayer.FileLocation.RelativeToStreamingAssetsFolder, Application.streamingAssetsPath + mp4Str, true);
        mediaplayer.m_Loop = false;
        mediaplayer.Play();
    }
    /// 
    /// AVPro事件管理
    /// 
    /// 
    /// 
    /// 
    void OnMediaPlayerEvent(MediaPlayer mp,MediaPlayerEvent.EventType et,ErrorCode errorCode)
    {
        switch (et)
        {
            case MediaPlayerEvent.EventType.Started:
                print("startedEvent开始事件触发");
                OnMediaPlayerStarted(mp);
                break;
            case MediaPlayerEvent.EventType.FinishedPlaying:
                print("finishedEvent结束事件触发");
                OnMediaPlayerFinished(mp);
                break;
        }
    }
    /// 
    /// 开始事件触发
    /// 
    /// 
    void OnMediaPlayerStarted(MediaPlayer mp)
    {
        print("开始事件触发的后续");
        
    }
    /// 
    /// 结束事件触发
    /// 
    /// 
    void OnMediaPlayerFinished(MediaPlayer mp)
    {
        print("结束事件触发的后续");
        if (mp.m_VideoPath.Contains("piantou"))
            SetMovie("/game2/time/movie.mp4");
        else if (mp.m_VideoPath.Contains("movie"))
            SetMovie("/game2/start/piantou.mp4");
    }
    // Update is called once per frame
    void Update () {
		
	}
}


你可能感兴趣的:(Unity视频插件AVPro Video的事件管理)