Unity3D AVProVideo开始播放跟播放完成

 Unity3D  AVProVideo开始播放跟播放完成

记录一下AVProVideo开始播放跟播放完成的注册事件,代码如下:

开始播放:mediaPlayer.Control.Play();

正在播放:mediaPlayer.VideoOpened     bool类型

关闭播放:mediaPlayer.CloseVideo();

播放路径:mediaPlayer.m_VideoPath     string类型

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

public class Test : MonoBehaviour {

    public Animation anim;
    public MediaPlayer mediaPlayer;
    public static bool isPlaying;
    public static Test _instance;
	void Start ()
    {
        _instance = this;
        mediaPlayer.Events.AddListener(OnMediaPlayerEvent);
    }

	void Update () {

       
	}
    void AnimPlay(string name, float speed, bool isBack)
    {
        if (isBack)
            anim[name].time = anim[name].clip.length;
        else
            anim[name].time = 0;
        anim.Play(name);
        anim[name].speed = speed;
    }
    public void MediaPlay(string clipName)
    {
        mediaPlayer.OpenVideoFromFile(MediaPlayer.FileLocation.RelativeToDataFolder, "VideoClip/" + clipName + ".mp4", false);
        mediaPlayer.Control.Play();
    }
    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;
            case MediaPlayerEvent.EventType.ReadyToPlay:
                Debug.Log("ReadyToPlay");
                break;
            case MediaPlayerEvent.EventType.FirstFrameReady:
                Debug.Log("First frame ready");
                break;

        }
    }
    private void OnMediaPlayerStarted(MediaPlayer mp)
    {
        isPlaying = true;
    }
    private void OnMediaPlayerFinished(MediaPlayer mp)
    {
        mediaPlayer.CloseVideo();
        isPlaying = false;
    }
}

 

你可能感兴趣的:(unity3D,C#,AVProVideo,unity3d,c#)