unity播放视频之AVProVideo使用

1.这是个点击播放视频,会弹下一个播放视频框自动播放(暂停背景音乐),点击关闭或者视频播放完成自动收起视频播放载体,继续播放背景音乐

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

public class OneVideo : MonoBehaviour {

    public DisplayUGUI m_displayUGUI;

    public MediaPlayer m_mediaplayerA;
    public MediaPlayer m_mediaplayerB;
    public MediaPlayer m_mediaplayerC;
    public MediaPlayer m_mediaplayerD;
    public GameObject videoCarrier;//视频载体

    public AudioSource BGMaudio;
    
    public void Playvideo(int i )
    {
        if (i == 0)
        {
            m_displayUGUI.CurrentMediaPlayer = m_mediaplayerA;
            m_mediaplayerA.Control.Rewind();
            m_mediaplayerA.Control.Play();
        }
        if (i == 1)
        {
            m_displayUGUI.CurrentMediaPlayer = m_mediaplayerB;
            m_mediaplayerB.Control.Rewind();
            m_mediaplayerB.Control.Play();

        }
        if (i == 2)
        {
            m_displayUGUI.CurrentMediaPlayer = m_mediaplayerC;
            m_mediaplayerC.Control.Rewind();
            m_mediaplayerC.Play();
           
        }
        if (i == 3)
        {
            m_displayUGUI.CurrentMediaPlayer = m_mediaplayerD;
            m_mediaplayerD.Control.Rewind();
            m_mediaplayerD.Play();
        }
        BGMaudio.Pause();
        videoCarrier.transform.DOLocalMoveY(0, 1.5f);
        
      
    }
    public void GuanbiVideo()
    {
        BGMaudio.Play();
        m_mediaplayerA.Stop();
        m_mediaplayerB.Stop();
        m_mediaplayerC.Stop();
        m_mediaplayerD.Stop();
        Tweener tween =  videoCarrier.transform.DOLocalMoveY(1150, 1.5f);
    }
    public void OnMediaPlayerEvent(MediaPlayer mp, MediaPlayerEvent.EventType et, ErrorCode errorCode)//播放完毕自动弹起
    {
        switch (et)
        {
          case MediaPlayerEvent.EventType.FinishedPlaying:
              
                GuanbiVideo();
                break;
        }
    }  


}

 

你可能感兴趣的:(unity播放视频之AVProVideo使用)