123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using UnityEngine;
- using UnityEngine.UI;
- public class TemplateVideo : BaseTemPlate
- {
- public static bool isPlayLock;
- public static bool isPlaying;
- public static Queue<TemplateVideo> temQueue = new Queue<TemplateVideo>();
- 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<TemplateVideo>();
- }
- 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 OnEnable autoplay1" + localSavePath);
- StartCoroutine(ADDAutoPlay());
- // m_Video.transform.GetComponent<VideoPlayBtn>().m_IsPlaying = false;
- // m_Video.transform.GetComponent<VideoPlayBtn>().PlayVideo();
- }
- else
- {
- Debug.Log("HJJ OnEnable autoplay2" + localSavePath);
- }
- setScale = true;
- }
- IEnumerator ADDAutoPlay()
- {
- yield return new WaitForSeconds(0.3f);
- Debug.Log("HJJ OnEnable" + localSavePath);
- temQueue.Enqueue(this);
- }
- // private MediaPlayer MediaPlayer;
- private bool setScale;
- protected override void OnAwake()
- {
- base.OnAwake();
- // m_VideoCtr = transform.Find("Screen/Video").GetComponent<Navigator.VideoControl>();
- m_Video = transform.Find("Screen/AVideo").GetComponent<AVProVideoPlayer>();
- //MediaPlayer = transform.Find("Screen/AVideo").GetComponent<MediaPlayer>();
- HideCollider();
-
-
- }
- private void Start()
- {
- if (!UserInfo.Instance.is20)
- {
- videoid = transform.name;
- spid = transform.parent.parent.name;
- MultiPlayerManager.Instance.OnSynVideo += OnSyncVideo;
- m_Video.transform.GetComponent<VideoPlayBtn>().spid = spid;
- m_Video.transform.GetComponent<VideoPlayBtn>().videoid = videoid;
- }
- mRawImage = transform.Find("Screen/Video").GetComponent<RawImage>();
- }
- 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<RectTransform>().sizeDelta = new Vector2(56,56*temp);
- // setScale = false;
- //}
- // ��Ƶԭʼ����
- if(mRawImage.texture!=null && setScale)
- {
- mRawImage.transform.parent.GetComponent<RectTransform>().localScale = new Vector3(mRawImage.transform.parent.GetComponent<RectTransform>().localScale.x, mRawImage.transform.parent.GetComponent<RectTransform>().localScale.x,mRawImage.transform.parent.GetComponent<RectTransform>().localScale.z);
- float temp = (float)mRawImage.texture.height / (float)mRawImage.texture.width;
- if(mRawImage.texture.height>mRawImage.texture.width)
- mRawImage.GetComponent<RectTransform>().sizeDelta = new Vector2(1.5f/temp,1.5f);
- else
- mRawImage.GetComponent<RectTransform>().sizeDelta = new Vector2(2,2*temp);
- setScale = false;
- }
- }
- public override void SetData(MaterialObjValue value, long 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 = 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<Navigator.VideoControl>();
- //m_VideoCtr.VideoURL = url;
- if (m_Video == null)
- m_Video = transform.Find("Screen/AVideo").GetComponent<AVProVideoPlayer>();
- m_Video.SetUrl(localSavePath);
- if (UserInfo.Instance.is20)
- {
- if (autoplay)
- {
- Debug.Log("HJJ OnEnable autoplay1" + localSavePath);
- StartCoroutine(ADDAutoPlay());
- }
- }
- }
- 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();
- }
- }
|