using System.Collections; using System.Collections.Generic; using RenderHeads.Media.AVProVideo; using UnityEngine; public class seturl : MonoBehaviour { public List mp; public List mpView; List urls = new List(); 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 urls) { this.urls = urls; } public void url(string url) { mp[0].CloseMedia(); this.urls = new List(); this.urls.Add(url); if(ctine!=null) StopCoroutine(ctine); ct = 0; ctine = StartCoroutine(playVieo()); } }