Unity VideoPlayer播放视频

VideoPlayer控制脚本,使用videoplayer组件控制视频频播放

/***********************
 * Title:   "VideoPlayer控制脚本"
 * Func:    
 * - videoplayer组件播放视频
 * UsedBy:  
 * Date:    2017.11.01
 * Author:  LHL.
 * Version: 1.0
 * Description:
 ***********************/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Video;
using UnityEngine.UI;
using UnityEngine.EventSystems;

public class VideoCtrl : MonoBehaviour {

    public static VideoCtrl instance;

    private VideoPlayer vPlayer;

    public GameObject videoImage;//播放Image
    private Button Kaishi,Zanting, BtnReStart;//开始,暂停,重播
    public Slider sliderVideo;//进度条
    private Button BtnX;//关闭
    private Image VideoPanel; //视频背景
    private Text NowTime;//播放时间
    private Text ZongTime;//总时间

    private float tt;  //视频总时长
    private float Index_t; //进度条计时时间

    private float shi,fen,miao;

    private bool IsPlay = true;
    // Use this for initialization
    void Awake () {
        instance = this;
        vPlayer = videoImage.GetComponent();
        Kaishi = GameObject.Find("Kaishi").GetComponent

Slider控制脚本,使用进度条控制视频进度,挂在给Slider

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;

public class SliderChange : MonoBehaviour, IDragHandler,IPointerClickHandler
{
    //拖动改变视频进度
    public void OnDrag(PointerEventData eventData)
    {
        VideoCtrl.instance.ChangeVideo(VideoCtrl.instance.sliderVideo.value);
    }
    //点击改变视频进度
    public void OnPointerClick(PointerEventData eventData)
    {
        VideoCtrl.instance.ChangeVideo(VideoCtrl.instance.sliderVideo.value);
    }
}

在WebGL上如果不能播放,可能是让它开始时自动播放了,需要手动点击播放
还是Edge浏览器牛批

你可能感兴趣的:(Unity VideoPlayer播放视频)