123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- using System.Collections;
- using System.Collections.Generic;
- using RenderHeads.Media.AVProVideo;
- using UnityEngine;
- public class seturl : MonoBehaviour
- {
- public List<MediaPlayer> mp;
- public List<GameObject> mpView;
- List<string> urls = new List<string>();
- int ct;
- int pl = 0;
- int hc = 1;
- Coroutine ctine;
- private void OnEnable()
- {
- ct = 0;
- ctine = StartCoroutine(playVieo());
- }
- private void OnDisable()
- {
- StopCoroutine(ctine);
- }
- IEnumerator playVieo()
- {
- while(true)
- {
- if(urls.Count>0)
- {
- if(mp.Count>1)
- {
- if (mp[pl] && mp[pl].Control != null && mp[pl].Control.IsPlaying())
- {
- // mp[pl].CloseMedia();
- yield return null;
- }
- if (!mpView[0].activeSelf && !mpView[1].activeSelf)
- {
- string url = urls[ct];
- // url = "https://sf1-cdn-tos.huoshanstatic.com/obj/media-fe/xgplayer_doc_video/hls/xgplayer-demo.m3u8";
- MediaPath mpath = new MediaPath(url, MediaPathType.AbsolutePathOrURL);
- mp[pl].OpenMedia(mpath, true);
- mp[pl].Play();
- }
- int hcct = ct;
- hcct++;
- if (hcct >= urls.Count)
- {
- hcct = 0;
- }
- string url2 = urls[hcct];
- // url2 = "https://sf1-cdn-tos.huoshanstatic.com/obj/media-fe/xgplayer_doc_video/hls/xgplayer-demo.m3u8";
- MediaPath mpath2 = new MediaPath(url2, MediaPathType.AbsolutePathOrURL);
- mp[hc].OpenMedia(mpath2, true);
- mp[hc].Play();
- mpView[pl].SetActive(true);
- mpView[hc].SetActive(true);
- int lspl = pl;
- pl = hc;
- hc = lspl;
- yield return new WaitForSeconds(20);
- while (!mp[pl].Control.IsPlaying())
- {
- mp[pl].Play();
- mpView[pl].SetActive(true);
- mpView[hc].SetActive(true);
- yield return new WaitForSeconds(2f);
- }
- ct++;
- if (ct >= urls.Count)
- {
- ct = 0;
- }
- }
- else
- {
- if (mp[0] && mp[0].Control != null && mp[0].Control.IsPlaying())
- {
- yield return null;
- }
- else
- {
- string url = urls[0];
- // url = "https://sf1-cdn-tos.huoshanstatic.com/obj/media-fe/xgplayer_doc_video/hls/xgplayer-demo.m3u8";
- MediaPath mpath = new MediaPath(url, MediaPathType.AbsolutePathOrURL);
- mp[0].OpenMedia(mpath, true);
- mpView[0].SetActive(true);
- mp[0].Play();
- }
- while (!mp[pl].Control.IsPlaying())
- {
- mp[0].Play();
- yield return new WaitForSeconds(2f);
- }
- }
- }
- else
- {
- yield return null;
- }
- }
- }
- public void url(List<string> urls)
- {
- this.urls = urls;
- }
- public void url(string url)
- {
- mp[0].CloseMedia();
- this.urls = new List<string>();
- this.urls.Add(url);
- if(ctine!=null)
- StopCoroutine(ctine);
- ct = 0;
- ctine = StartCoroutine(playVieo());
- }
- }
|