赞
踩
【参数详解】
①修改Source类型为URL
②Play On Awake去掉勾选,由程序控制。
如果没有StreamingAssets文件夹,那么自己就新建一个。
using UnityEngine; using UnityEngine.UI; using UnityEngine.Video; public class VideoView : MonoBehaviour { public RawImage mRawImage; public VideoPlayer mVideoPlayer; public RenderTexture rt; //跳过按钮 public Button skipBtn; private bool bStop = false; void Start() { if (skipBtn != null) { skipBtn.onClick.AddListener(OnSkipBtn); } //视频播放结束事件 mVideoPlayer.loopPointReached += OnMediaPlayerEvent; } public void OnMediaPlayerEvent(VideoPlayer source) { if (bStop) return; Stop(); } //播放视频 public void Play(string videoPath) { bStop = false; mRawImage.texture = rt; mVideoPlayer.url = Application.streamingAssetsPath + "/" + videoPath; ; mVideoPlayer.Play(); } //暂停 public void Pause() { mVideoPlayer.Pause(); } //跳过 void OnSkipBtn() { Stop(); } //停止 public void Stop() { if (bStop) return; bStop = true; mVideoPlayer.Stop(); } private void OnDestroy() { mVideoPlayer.loopPointReached -= OnMediaPlayerEvent; } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。