using System.Collections; using System.Collections.Generic; using System.IO; using RenderHeads.Media.AVProVideo; using UnityEngine; using UnityEngine.UI; public class TemplateVideo : BaseTemPlate { public static bool isPlayLock; public static bool isPlaying; public static Queue temQueue = new Queue(); private Navigator.VideoControl m_VideoCtr; public AVProVideoPlayer m_Video; public string localSavePath; public string spid; public string videoid; public bool autoplay; private void OnDisable() { TemplateVideo.isPlaying = false; Debug.Log("HJJ 停止播放"); m_Video.Stop(); if (temQueue.Count>0) temQueue = new Queue(); } protected override void OnEnable() { //localSavePath = Application.persistentDataPath + "/Material/" + Path.GetFileName(Data.downloadPath); base.OnEnable(); if (GameManager.Instance.IsRuning && string.IsNullOrWhiteSpace(m_Video.GetUrl())) { if (File.Exists(localSavePath)) { m_Video.SetUrl(localSavePath); } else { m_Video.SetUrl(null); } } GameManager.Instance.text.text += localSavePath + "\n"; if (autoplay) { Debug.Log("HJJ 开始自动播放" + localSavePath); StartCoroutine(ADDAutoPlay()); // m_Video.transform.GetComponent().m_IsPlaying = false; // m_Video.transform.GetComponent().PlayVideo(); } else { Debug.Log("HJJ 不需要自動播放" + localSavePath); } setScale = true; } IEnumerator ADDAutoPlay() { yield return new WaitForSeconds(0.3f); Debug.Log("HJJ 开始自动播放加入數組" + localSavePath); temQueue.Enqueue(this); } // private MediaPlayer MediaPlayer; private bool setScale; protected override void OnAwake() { base.OnAwake(); // m_VideoCtr = transform.Find("Screen/Video").GetComponent(); m_Video = transform.Find("Screen/AVideo").GetComponent(); //MediaPlayer = transform.Find("Screen/AVideo").GetComponent(); HideCollider(); } private void Start() { if (!UserInfo.Instance.is20) { videoid = transform.name; spid = transform.parent.parent.name; MultiPlayerManager.Instance.OnSynVideo += OnSyncVideo; m_Video.transform.GetComponent().spid = spid; m_Video.transform.GetComponent().videoid = videoid; } mRawImage = transform.Find("Screen/Video").GetComponent(); } private RawImage mRawImage; private void Update() { //if((MediaPlayer.Info.GetVideoHeight()!=0 || MediaPlayer.Info.GetVideoWidth()!=0) && setScale ) //{ // float temp = (float)MediaPlayer.Info.GetVideoHeight() / (float)MediaPlayer.Info.GetVideoWidth(); // MediaPlayer.transform.GetComponent().sizeDelta = new Vector2(56,56*temp); // setScale = false; //} // 视频原始比例 if(mRawImage.texture!=null && setScale) { mRawImage.transform.parent.GetComponent().localScale = new Vector3(mRawImage.transform.parent.GetComponent().localScale.x, mRawImage.transform.parent.GetComponent().localScale.x,mRawImage.transform.parent.GetComponent().localScale.z); float temp = (float)mRawImage.texture.height / (float)mRawImage.texture.width; if(mRawImage.texture.height>mRawImage.texture.width) mRawImage.GetComponent().sizeDelta = new Vector2(1.5f/temp,1.5f); else mRawImage.GetComponent().sizeDelta = new Vector2(2,2*temp); setScale = false; } } public override void SetData(MaterialObjValue value, int updateTime) { base.SetData(value, updateTime); if (!GameManager.Instance.IsRuning|| Data == null) { localSavePath = Application.persistentDataPath + "/Material/" + Path.GetFileName(value.DownloadPath); // DownloadManager.Instance.AddDownloadData(Data); DownLoadMaterial data = new DownLoadMaterial(); data.downLoadPath = value.DownloadPath; data.localLoadPath = Application.persistentDataPath + "/Material/" + Path.GetFileName(value.DownloadPath); data.updataTime = GameManager.Instance.m_SceneValue.updateTime; data.type = "3"; MsgHandler.AddListener(value.DownloadPath, HandleMsg); DownloadResManager.Instance.DownLoad(data); Debug.Log(" SetData " + updateTime); Data = data; } else { localSavePath = Application.persistentDataPath + "/Material/" + Path.GetFileName(value.DownloadPath); if (File.Exists(localSavePath)) { // m_VideoCtr.VideoURL = Data.localSavePath; m_Video.SetUrl(localSavePath); } else { // m_VideoCtr.VideoURL = null; m_Video.SetUrl(null); } } } public void SetData(string url) { Debug.Log(url); localSavePath = Application.persistentDataPath + "/Material/" + Path.GetFileName(url); //if(m_VideoCtr ==null) // m_VideoCtr = transform.Find("Screen/Video").GetComponent(); //m_VideoCtr.VideoURL = url; if (m_Video == null) m_Video = transform.Find("Screen/AVideo").GetComponent(); m_Video.SetUrl(localSavePath); } private void HandleMsg(Msg msg) { Debug.Log("DGJ ===> TemplateVideo"); if (File.Exists(localSavePath)) { // m_VideoCtr.VideoURL = Data.localSavePath; m_Video.SetUrl(localSavePath); } else { // m_VideoCtr.VideoURL = null; m_Video.SetUrl(null); } } private void OnSyncVideo(SyncVideoData syncVideo) { if(syncVideo.spid == spid&& syncVideo.id == videoid) { if (syncVideo.isPlay) m_Video.Play(); else m_Video.Pause(); if (syncVideo.times != -1) m_Video.SetSeek(syncVideo.times); } } public override void HideCollider() { base.HideCollider(); } }