217 lines
3.9 KiB
C#
217 lines
3.9 KiB
C#
using BitStrap;
|
|
using Crosstales.Radio;
|
|
using Crosstales.Radio.Model;
|
|
using Crosstales.Radio.Util;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
|
|
[HelpURLAttribute("https://www.crosstales.com/media/data/assets/radio/api/class_crosstales_1_1_radio_1_1_demo_1_1_g_u_i_radio_static.html")]
|
|
public class RadioStationWidget : MonoBehaviour
|
|
{
|
|
[Tooltip("'RadioPlayer' from the scene.")]
|
|
[Header("Settings")]
|
|
public RadioPlayer Player;
|
|
|
|
public RadioStation radioStation;
|
|
|
|
[Tooltip("The color for the Play-mode.")]
|
|
public Color32 PlayColor = new Color32(0, byte.MaxValue, 0, 64);
|
|
|
|
[ReadOnly]
|
|
public Color32 NormalColor = Color.white;
|
|
|
|
[Tooltip("How many times should the radio station restart after an error before giving up (default: 3).")]
|
|
public int Retries = 3;
|
|
|
|
[Header("UI Objects")]
|
|
public InputField Name;
|
|
|
|
public Text Station;
|
|
|
|
public InputField Url;
|
|
|
|
public InputField Bitrate;
|
|
|
|
public InputField Genere;
|
|
|
|
public InputField Rating;
|
|
|
|
public Text Format;
|
|
|
|
public Text SongTitle;
|
|
|
|
public Toggle favoriteToggle;
|
|
|
|
public Text Elapsed;
|
|
|
|
public GameObject PlayButton;
|
|
|
|
public GameObject StopButton;
|
|
|
|
public Image MainImage;
|
|
|
|
private Color32 color;
|
|
|
|
private int invokeDelayCounter = 1;
|
|
|
|
private bool isStopped = true;
|
|
|
|
private int playtime;
|
|
|
|
public void Initialize()
|
|
{
|
|
Name.textComponent.text = radioStation.Name;
|
|
Station.text = Helper.CleanUrl(radioStation.Station);
|
|
Genere.textComponent.text = radioStation.Genres;
|
|
favoriteToggle.isOn = radioStation.Rating >= 6f;
|
|
}
|
|
|
|
public void Update()
|
|
{
|
|
}
|
|
|
|
public void OnDestroy()
|
|
{
|
|
}
|
|
|
|
public void Play()
|
|
{
|
|
RadioManager.Instance.simplePlayer.RadioStation = radioStation;
|
|
RadioManager.Instance.Play(false);
|
|
RadioManager.Instance.radioWindow.StopAllStations();
|
|
SetState(true);
|
|
EventSystem.current.SetSelectedGameObject(StopButton.gameObject);
|
|
}
|
|
|
|
public void Stop()
|
|
{
|
|
RadioManager.Instance.Stop();
|
|
SetState(false);
|
|
EventSystem.current.SetSelectedGameObject(PlayButton.gameObject);
|
|
}
|
|
|
|
public void OpenUrl()
|
|
{
|
|
Application.OpenURL(radioStation.Station);
|
|
}
|
|
|
|
public void ChangeVolume(float volume)
|
|
{
|
|
if (Player != null && Player.Source != null)
|
|
{
|
|
Player.Source.volume = volume;
|
|
}
|
|
}
|
|
|
|
public void NameChanged(string name)
|
|
{
|
|
radioStation.Name = name;
|
|
}
|
|
|
|
public void StationChanged(string station)
|
|
{
|
|
radioStation.Station = station;
|
|
}
|
|
|
|
public void UrlChanged(string url)
|
|
{
|
|
radioStation.Url = url;
|
|
}
|
|
|
|
public void GenresChanged(string genres)
|
|
{
|
|
radioStation.Genres = genres;
|
|
}
|
|
|
|
public void BitrateChanged(string bitrateString)
|
|
{
|
|
int result;
|
|
if (int.TryParse(bitrateString, out result))
|
|
{
|
|
radioStation.Bitrate = Helper.NearestBitrate(result, radioStation.Format);
|
|
}
|
|
if (Bitrate != null)
|
|
{
|
|
Bitrate.text = radioStation.Bitrate.ToString();
|
|
}
|
|
}
|
|
|
|
public void RatingChanged(string ratingString)
|
|
{
|
|
float result;
|
|
if (float.TryParse(ratingString, out result))
|
|
{
|
|
radioStation.Rating = Mathf.Clamp(result, 0f, 6f);
|
|
}
|
|
if (Rating != null)
|
|
{
|
|
Rating.text = radioStation.Rating.ToString();
|
|
}
|
|
}
|
|
|
|
public void OpenSpotifyUrl()
|
|
{
|
|
if (Player != null)
|
|
{
|
|
Application.OpenURL(Player.RecordInfo.SpotifyUrl);
|
|
}
|
|
}
|
|
|
|
public void SetState(bool play)
|
|
{
|
|
PlayButton.SetActive(!play);
|
|
StopButton.SetActive(play);
|
|
SetSelection(play);
|
|
}
|
|
|
|
public void SetSelection(bool play)
|
|
{
|
|
MainImage.color = ((!play) ? NormalColor : PlayColor);
|
|
}
|
|
|
|
public void OnFavoriteChange()
|
|
{
|
|
if (favoriteToggle.isOn)
|
|
{
|
|
radioStation.Rating = 6f;
|
|
}
|
|
else
|
|
{
|
|
radioStation.Rating = 0f;
|
|
}
|
|
}
|
|
|
|
private void onPlayBackStart(RadioStation station)
|
|
{
|
|
}
|
|
|
|
private void onPlaybackEnd(RadioStation station)
|
|
{
|
|
}
|
|
|
|
private void onAudioStart(RadioStation station)
|
|
{
|
|
}
|
|
|
|
private void onAudioEnd(RadioStation station)
|
|
{
|
|
}
|
|
|
|
private void onAudioPlayTime(RadioStation station, float playtime)
|
|
{
|
|
}
|
|
|
|
private void onBufferingProgress(RadioStation station, float progress)
|
|
{
|
|
}
|
|
|
|
private void onErrorInfo(RadioStation station, string info)
|
|
{
|
|
}
|
|
|
|
private void play()
|
|
{
|
|
}
|
|
}
|