Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine.Video;
- using Mirror;
- using YoutubePlayer;
- namespace Era.Modules.Props
- {
- public class Television : Prop
- {
- public VideoPlayer Player;
- private double _StoredTime;
- public override void OnStartClient()
- {
- Player.prepareCompleted += PrepareCompleted;
- CmdUpdateState();
- }
- public override void Interact(Player player)
- {
- // TODO: Open UI
- }
- [ClientRpc]
- private void RpcPlayFile(string file)
- {
- SharedPlayFile(file, 0, true);
- }
- [Command(ignoreAuthority = true)]
- private void CmdRequestFile(string file)
- {
- ServerRequestFile(file);
- }
- public void ServerRequestFile(string file)
- {
- file = PreProcessURL(file);
- RpcPlayFile(file);
- SharedPlayFile(file, 0, true);
- }
- [Command(ignoreAuthority = true)]
- private void CmdUpdateState(NetworkConnectionToClient conn = null)
- {
- RpcUpdateState(conn, Player.url, Player.time, Player.isPlaying);
- }
- [TargetRpc]
- private void RpcUpdateState(NetworkConnection conn, string file, double time, bool play)
- {
- SharedPlayFile(file, time, play);
- }
- private void SharedPlayFile(string file, double time, bool play)
- {
- Player.url = file;
- _StoredTime = time;
- if (play) {
- Player.Prepare();
- }
- }
- private void PrepareCompleted(object sender)
- {
- Player.time = _StoredTime;
- Player.Play();
- }
- private string PreProcessURL(string url)
- {
- if (url.Contains("youtube")) {
- YoutubeVideoMetaData meta = YoutubeDl.GetVideoMetaData(url, YoutubeDlOptions.Default);
- url = meta.Url;
- }
- return url;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement