using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Video; using System; using UnityEngine.UI; namespace Navigator { public class VideoControl : MonoBehaviour { public GameObject Icon; public Material material; public VideoPlayer videoPlayer; public RawImage VideoPage; public RawImage FengMian; [SerializeField] private string m_VideoURL; public string VideoURL { get { return m_VideoURL; } set { m_VideoURL = value; if (!string.IsNullOrWhiteSpace(m_VideoURL)) { videoPlayer.url =/* "file://" + */m_VideoURL; } } } public bool m_IsPlaying; private void OnEnable() { if (videoPlayer != null) { if (VideoPage.texture == null) { RenderTexture texture = new RenderTexture(1024, 1024, 16, RenderTextureFormat.ARGB32); VideoPage.texture = texture; videoPlayer.targetTexture = texture; } FengMian.gameObject.SetActive(true); videoPlayer.Stop(); videoPlayer.targetTexture.Release(); Icon.SetActive(true); m_IsPlaying = false; videoPlayer.errorReceived += OnErrorReceived; videoPlayer.loopPointReached += VideoPlayerEnd; } } private void VideoPlayerEnd(VideoPlayer source) { if (videoPlayer != null) { FengMian.gameObject.SetActive(true); videoPlayer.Stop(); videoPlayer.targetTexture.Release(); Icon.SetActive(true); m_IsPlaying = false; } } private void OnErrorReceived(VideoPlayer source, string message) { Debug.LogError(message); } public void PlayVideo() { Debug.Log("m_IsPlaying: " + m_IsPlaying); if (videoPlayer == null) return; Debug.Log(videoPlayer.url); if (!m_IsPlaying) { FengMian.gameObject.SetActive(false); videoPlayer.Play(); Icon.SetActive(false); } else { videoPlayer.Pause(); Icon.SetActive(true); } m_IsPlaying = !m_IsPlaying; } private void OnDisable() { videoPlayer.errorReceived -= OnErrorReceived; videoPlayer.loopPointReached -= VideoPlayerEnd; } } public class VideoInfo { public VideoClip Clip; public string VideoUrl; //public int index; } }