Hi,
I have 5 panels which dispaying videos. How to make queue of actions where action is something like this:
//VideoController
public void OnOpenVideoFile()
{
_mediaPlayer.m_VideoPath = System.IO.Path.Combine(_folder, _videoFiles[_VideoIndex]);
_VideoIndex = (_VideoIndex + 1) % (_videoFiles.Length);
if (string.IsNullOrEmpty(_mediaPlayer.m_VideoPath))
{
_mediaPlayer.CloseVideo();
_VideoIndex = 0;
}
else
{
_mediaPlayer.OpenVideoFromFile(MediaPlayer.FileLocation.RelativeToStreamingAssetsFolder, _mediaPlayer.m_VideoPath, false);
}
}
To add item to queue:
//Controller
private Queue<VideoController> m_VideoControllers = new Queue<VideoController>();
void Start()
{
m_VideoControllers.Enqueue(newVideoController1);
m_VideoControllers.Enqueue(newVideoController2);
}
My queuing mechanism:
void Update()
{
if (m_VideoControllers.Count > 0 && !isBlocked)
{
loadingBar.SetActive(true);
isBlocked = true;
var item = m_VideoControllers.Dequeue();
StartCoroutine(WaitForOpenVideo(item));
item.OnOpenVideoFile();
}
else
{
if (m_VideoControllers.Count == 0 && !isBlocked )
loadingBar.SetActive(false);
}
}
private IEnumerator WaitForOpenVideo(VideoController item)
{
do {
if (item._mediaPlayer.Control.CanPlay())
isBlocked = false;
yield return null;
} while (isBlocked);
}
After few secund, will be loaded new videos.
What is the best way to implement queuing mechanism?
How can I improve my code?