赞
踩
2020年4月1日更新:发现AVPro Video插件,有官方示例,如图
,之下我写的仅供参考
(本来想用NGUI,但发现它在AVPro的视频前,显示不出来)
控制脚本clit.cs及重要注释一二三四
using System.Collections; using System.Collections.Generic; using UnityEngine; using RenderHeads.Media.AVProVideo; using UnityEngine.UI; public class clit : MonoBehaviour { public MediaPlayer med; public Slider slider; float volume; float time; private int i; public GameObject CtrlBtn; // Use this for initializa void Start() { med.OpenVideoFromFile(MediaPlayer.FileLocation.RelativeToStreamingAssetsFolder, "1.mp4", med.m_AutoStart);//一、导入的视频自动播放 // Debug.Log(med.name); } // Update is called once per frame void Update() { // if (med && med.Info != null && med.Info.GetDurationMs() == 1) if (med && med.Info != null) { time = med.Control.GetCurrentTimeMs(); volume = time / med.Info.GetDurationMs(); slider.value = volume;//二、视频播放到哪里,进度条就到哪里 } } public void OnVideoSeekSlider()//三、拖动进度条时,视频也变到此位置——UI界面,进度条Slider的监听函数 { if (med && slider && slider.value != volume) { med.Control.Seek(slider.value * med.Info.GetDurationMs()); } } public void onPlay() { if (med) { med.Control.Play(); } } public void OnPause() { if (med) { med.Control.Pause(); } } public void onPlayOrPause()//四、UI界面,播放停止按钮的监听函数 { i++; if (med&&i%2==1) { med.Control.Pause(); CtrlBtn.GetComponent<Image>().sprite = Resources.Load("暂停", typeof(Sprite)) as Sprite; } else if (med) { med.Control.Play(); CtrlBtn.GetComponent<Image>().sprite = Resources.Load("播放", typeof(Sprite)) as Sprite; } } }
注意进度条的锚定:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。