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;
    // Start is called before the first frame update
    void Start()
    {
        ct = 0;
        StartCoroutine(playVieo());


    }

    IEnumerator playVieo()
    {
        while(true)
        {
            if(urls.Count>0)
            {
                if(!mpView[0].activeSelf&& !mpView[1].activeSelf)
                {
                    string url = urls[ct];
                    MediaPath mpath = new MediaPath(url, MediaPathType.AbsolutePathOrURL);
                    mp[pl].OpenMedia(mpath, true);
                }


                int hcct = ct;
                hcct++;
                if (hcct >= urls.Count)
                {
                    hcct = 0;
                }
                string url2 = urls[hcct];
                MediaPath mpath2 = new MediaPath(url2, MediaPathType.AbsolutePathOrURL);
                mp[hc].OpenMedia(mpath2, true);

                mpView[pl].SetActive(true);
                mpView[hc].SetActive(false);

                int lspl = pl;
                pl = hc;
                hc = lspl;

                yield return new WaitForSeconds(20);

                while(!mp[pl].Control.IsPlaying())
                {
                    yield return null;
                }

                ct++;
                if (ct >= urls.Count)
                {
                    ct = 0;
                }
            }
            else
            {
                yield return null;
            }
        }
    }

    public void url(List<string> urls)
    {
        this.urls = urls;
    }


}