Video controls
Buttons for an ST Video Player: two songs, play, pause, stop, jump 10 seconds and a sync mode switch kept in a synced bool, so every device loads the next video in the same mode. The label shows the position, the requester and the last video event.
VideoControls.cs
using StageTime.SDK;
using TMPro;
using UnityEngine;
/// <summary>
/// On an STVideoPlayer: buttons load two karaoke videos, play, pause, stop, jump 10 s and switch the sync mode
/// (a synced bool, applied on every device; it is used from the next load). The label shows the state, position,
/// mode, requester and the last video event.
/// </summary>
public class VideoControls : StageTimeBehaviour
{
public TMP_Text label;
public string songA = "https://videos.karaokecentral.com/fixyou.mp4";
public string songB = "https://videos.karaokecentral.com/askyfullofstars.mp4";
[Synced] private bool requesterMode;
private STVideoPlayer video;
private string lastEvent = "-";
private float nextLabelTime;
private void Start()
{
video = GetComponent<STVideoPlayer>();
ApplyMode();
}
public void PlaySongA() => video.PlayURL(songA);
public void PlaySongB() => video.PlayURL(songB);
public void PlayVideo() => video.Play();
public void PauseVideo() => video.Pause();
public void StopVideo() => video.Stop();
public void Back10() => video.SetTime(Mathf.Max(0f, video.time - 10f));
public void Forward10() => video.SetTime(video.time + 10f);
public void ToggleMode()
{
Networking.SetOwner(Networking.LocalPlayer, gameObject);
requesterMode = !requesterMode;
ApplyMode();
}
public override void OnDeserialization() => ApplyMode();
public override void OnVideoStart() => lastEvent = "Start";
public override void OnVideoPlay() => lastEvent = "Play";
public override void OnVideoPause() => lastEvent = "Pause";
public override void OnVideoEnd() => lastEvent = "End";
public override void OnVideoError() => lastEvent = "Error";
private void ApplyMode()
{
if (video != null) video.syncMode = requesterMode ? STVideoSyncMode.SyncToRequester : STVideoSyncMode.Sync;
}
private void Update()
{
if (label == null || video == null || Time.time < nextLabelTime) return;
nextLabelTime = Time.time + 0.1f;
string state = video.isPlaying ? "Playing" : video.isPaused ? "Paused" : "Stopped";
StageTimePlayer requester = video.requester;
label.text = state + " " + video.time.ToString("0.0") + " / " + video.duration.ToString("0.0") + " s"
+ "\nMode: " + (requesterMode ? "Sync To Requester" : "Sync") + " (from the next load)"
+ "\nRequester: " + (requester != null ? requester.displayName : "-") + " Last event: " + lastEvent;
}
}