132 lines
2.5 KiB
C#
132 lines
2.5 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.IO;
|
|
using Crosstales.Radio.Model;
|
|
using UnityEngine;
|
|
|
|
namespace Crosstales.Radio.Demo
|
|
{
|
|
public class TestAllStations : MonoBehaviour
|
|
{
|
|
public BasePlayer Player;
|
|
|
|
public RadioManager Manager;
|
|
|
|
public string ErrorFilePath;
|
|
|
|
private bool stopped = true;
|
|
|
|
private bool error;
|
|
|
|
private int errorCount;
|
|
|
|
public void Start()
|
|
{
|
|
if (Player != null)
|
|
{
|
|
Player.isLegacyMode = true;
|
|
}
|
|
}
|
|
|
|
public void OnEnable()
|
|
{
|
|
if (Player != null)
|
|
{
|
|
Player.OnAudioStart += onAudioStart;
|
|
Player.OnAudioEnd += onAudioEnd;
|
|
Player.OnErrorInfo += onErrorInfo;
|
|
}
|
|
if (Manager != null)
|
|
{
|
|
Manager.OnProviderReady += onProviderReady;
|
|
}
|
|
}
|
|
|
|
public void OnDisable()
|
|
{
|
|
if (Player != null)
|
|
{
|
|
Player.OnAudioStart -= onAudioStart;
|
|
Player.OnAudioEnd -= onAudioEnd;
|
|
Player.OnErrorInfo -= onErrorInfo;
|
|
}
|
|
if (Manager != null)
|
|
{
|
|
Manager.OnProviderReady -= onProviderReady;
|
|
}
|
|
}
|
|
|
|
private IEnumerator verify()
|
|
{
|
|
WaitForSeconds wait = new WaitForSeconds(1f);
|
|
if (Manager != null)
|
|
{
|
|
Debug.Log("Verification started: " + Manager.Stations.Count);
|
|
foreach (RadioStation station in Manager.Stations)
|
|
{
|
|
Player.RadioStation = station;
|
|
Player.Play();
|
|
while (stopped && !error)
|
|
{
|
|
yield return null;
|
|
}
|
|
yield return wait;
|
|
Player.Stop();
|
|
while (!stopped && !error)
|
|
{
|
|
yield return null;
|
|
}
|
|
yield return wait;
|
|
error = false;
|
|
}
|
|
Debug.Log("Verification ended: " + errorCount + "/" + Manager.Stations.Count);
|
|
if (errorCount != Manager.Stations.Count)
|
|
{
|
|
Debug.LogError("Stations with errors found!");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Debug.LogWarning("'Manager' is null!");
|
|
}
|
|
}
|
|
|
|
private void onAudioStart(RadioStation station)
|
|
{
|
|
stopped = false;
|
|
}
|
|
|
|
private void onAudioEnd(RadioStation station)
|
|
{
|
|
stopped = true;
|
|
}
|
|
|
|
private void onErrorInfo(RadioStation station, string info)
|
|
{
|
|
Debug.LogWarning(string.Concat("Error: ", station, " - ", info));
|
|
if (!string.IsNullOrEmpty(ErrorFilePath))
|
|
{
|
|
try
|
|
{
|
|
using (StreamWriter streamWriter = new StreamWriter(ErrorFilePath, true))
|
|
{
|
|
streamWriter.WriteLine(station.ToString());
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Debug.LogError("Could not write to file: " + ex);
|
|
}
|
|
}
|
|
stopped = true;
|
|
error = true;
|
|
errorCount++;
|
|
}
|
|
|
|
private void onProviderReady()
|
|
{
|
|
StartCoroutine(verify());
|
|
}
|
|
}
|
|
}
|