diff --git a/LoopToggle.cs b/LoopToggle.cs index 176cfe4..1c5f993 100644 --- a/LoopToggle.cs +++ b/LoopToggle.cs @@ -4,11 +4,11 @@ using VRC.SDKBase; using VRC.SDK3.Video.Components.Base; -namespace UdonVR.Takato +namespace UdonVR.Takato.VideoPlayer { public class LoopToggle : UdonSharpBehaviour { - public BaseVRCVideoPlayer videoPlayer; + public UdonSyncVideoPlayer videoPlayer; [UdonSynced] bool _loopSynced; @@ -23,14 +23,12 @@ private void ToggleValue(bool value) loopToggle.isOn = value; loopToggle.enabled = true; } - private void Start() + + public void Init() { - if (Networking.IsMaster) - { - _loopSynced = videoPlayer.Loop; - _loop = _loopSynced; - ToggleValue(_loopSynced); - } + _loopSynced = videoPlayer.videoPlayer.Loop; + _loop = _loopSynced; + ToggleValue(_loopSynced); } public void ToggleButton() //Call RunProgram on this method @@ -48,7 +46,9 @@ public void ToggleButton() //Call RunProgram on this method private void DoToggle() { _loop = _loopSynced; - videoPlayer.Loop = _loopSynced; + videoPlayer.avProVideoPlayer.Loop = _loopSynced; + videoPlayer.unityVideoPlayer.Loop = _loopSynced; + //videoPlayer.Loop = _loopSynced; if (!Networking.IsMaster) { ToggleValue(_loopSynced); diff --git a/MasterOnly.cs b/MasterOnly.cs index 2e995b5..9321911 100644 --- a/MasterOnly.cs +++ b/MasterOnly.cs @@ -3,6 +3,7 @@ using UnityEngine.UI; using VRC.SDK3.Components; using VRC.SDKBase; +using UdonVR.Takato.VideoPlayer; namespace UdonVR.Takato { @@ -15,9 +16,9 @@ public class MasterOnly : UdonSharpBehaviour public Button pauseButton; public Button stopButton; public Slider timeBar; - [UdonSynced] public bool syncedMasterOnly; + [UdonSynced] public bool syncedMasterOnly = true; private bool _masterOnly; - + private bool _isCurrentMaster; private void Start() { @@ -26,6 +27,8 @@ private void Start() masterToggle.isOn = syncedMasterOnly; //MasterTogle(); } + _isCurrentMaster = Networking.IsMaster; + } public void MasterToggleButton() //Call RunProgram on this method @@ -64,7 +67,14 @@ public override void OnOwnershipTransferred() timeBar.interactable = videoPlayer.EnableTimeBar(); } } - + public override void OnPlayerLeft(VRCPlayerApi player) + { + if (!_isCurrentMaster && Networking.IsMaster) + { + _isCurrentMaster = true; + OnOwnershipTransferred(); + } + } public override void OnDeserialization() { if (!Networking.IsMaster) diff --git a/PanelController.cs b/PanelController.cs new file mode 100644 index 0000000..ab21f55 --- /dev/null +++ b/PanelController.cs @@ -0,0 +1,73 @@ + +using System; +using UdonSharp; +using UnityEngine; +using VRC.SDK3.Components; +using VRC.SDKBase; +using VRC.Udon; + +namespace UdonVR.Takato.VideoPlayer +{ + /// + /// + /// + public class PanelController : UdonSharpBehaviour + { + public PanelUI[] panels; + + public void AutoResyncToggle(bool value) + { + foreach (PanelUI Panel in panels) + { + Panel.AutoResyncToggle(value); + } + } + public void AutoResyncRateInput(int value) + { + foreach (PanelUI Panel in panels) + { + Panel.AutoResyncRateInput(value); + } + } + + public void SetOwnerText(string displayName) + { + foreach (PanelUI Panel in panels) + { + Panel.SetOwnerText(displayName); + } + } + + public void SetVideoTimeBarMaxValue(float value) + { + foreach (PanelUI Panel in panels) + { + Panel.SetVideoTimeBarMaxValue(value); + } + } + + public void SetVideoTimeBarValue(int value) + { + foreach (PanelUI Panel in panels) + { + Panel.SetVideoTimeBarValue(value); + } + } + + public void VideoTimeBarInteractable(bool value) + { + foreach (PanelUI Panel in panels) + { + Panel.VideoTimeBarInteractable(value); + } + } + + public void SetResyncText(string value) + { + foreach (PanelUI Panel in panels) + { + Panel.SetResyncText(value); + } + } + } +} diff --git a/PanelUI.cs b/PanelUI.cs new file mode 100644 index 0000000..a07a53a --- /dev/null +++ b/PanelUI.cs @@ -0,0 +1,96 @@ +using System; +using TMPro; +using UdonSharp; +using UnityEngine; +using UnityEngine.UI; +using VRC.SDK3.Components; +using VRC.SDKBase; +using VRC.Udon; + +namespace UdonVR.Takato.VideoPlayer +{ + /// + /// + /// + public class PanelUI : UdonSharpBehaviour + { + public UdonSyncVideoPlayer UdonSyncVideoPlayer; + public GameObject autoResyncFilled; + public TextMeshProUGUI resyncText; + public InputField autoResyncRateInput; + public Text ownerText; + public Slider videoTimeBar; + public Text videoTimeBarText; + + public void AutoResyncToggle(bool value) + { + if (Utilities.IsValid(autoResyncFilled)) + { + autoResyncFilled.SetActive(value); + } + } + + public void AutoResyncSet() + { + if (Utilities.IsValid(autoResyncRateInput)) + { + if (!string.IsNullOrEmpty(autoResyncRateInput.text.Trim())) + return; + + int temp; + int.TryParse(autoResyncRateInput.text, out temp); + UdonSyncVideoPlayer.AutoResyncSet(temp); + autoResyncRateInput.text = string.Empty; + + } + } + public void AutoResyncRateInput(int value) + { + if (Utilities.IsValid(autoResyncRateInput)) + { + ((Text)autoResyncRateInput.placeholder).text= value.ToString(); + + } + } + + public void SetOwnerText(string displayName) + { + if (Utilities.IsValid(ownerText)) + { + ownerText.text = displayName; + } + } + + public void SetVideoTimeBarValue(int value) + { + if (Utilities.IsValid(videoTimeBar)) + { + videoTimeBar.value = value; + } + } + + public void SetVideoTimeBarMaxValue(float value) + { + if (Utilities.IsValid(videoTimeBar)) + { + videoTimeBar.maxValue = value; + } + } + + public void VideoTimeBarInteractable(bool value) + { + if (Utilities.IsValid(videoTimeBar)) + { + videoTimeBar.interactable = value; + } + } + + public void SetResyncText(string value) + { + if (Utilities.IsValid(resyncText)) + { + resyncText.text = value; + } + } + } +} diff --git a/StutterDetector.cs b/StutterDetector.cs new file mode 100644 index 0000000..a38c6fb --- /dev/null +++ b/StutterDetector.cs @@ -0,0 +1,76 @@ + +using UdonSharp; +using UnityEngine; +using VRC.SDKBase; +using VRC.Udon; +using UnityEngine.UI; +using UdonVR.Takato.VideoPlayer; + +namespace UdonVR +{ + public class StutterDetector : UdonSharpBehaviour + { + public UdonSyncVideoPlayer VideoPlayer; + public float Target = 2f; + public GameObject TargetObj; + public InputField Inputfeild; + public GameObject ParentDebug; + + private bool isDebug = false; + private Text[] DebugChildren; + private int ChildCount = 0; + private int CurrentChild = 0; + private float OldTime = 10f; + private float CurTime = 0; + void Start() + { + if (ParentDebug != null) + { + DebugChildren = ParentDebug.transform.GetComponentsInChildren(); + ChildCount = DebugChildren.Length - 1; + reset(); + isDebug = true; + } + } + + private void Update() + { + if (VideoPlayer.autoResync) + { + CurTime = Time.deltaTime; + + if (CurTime > OldTime * Target) + { + VideoPlayer.ForceSyncVideo(); + } + + if (isDebug) DebugOut(); + + OldTime = Time.deltaTime; + } + } + + public void reset() + { + if (TargetObj != null) + TargetObj.SetActive(false); + } + + public void SetTarget() + { + Target = float.Parse(Inputfeild.text); + } + + private void DebugOut() + { + if (CurTime > OldTime * Target) + { + if (TargetObj != null) + TargetObj.SetActive(true); + } + DebugChildren[CurrentChild].text = CurTime.ToString(); + CurrentChild++; + if (CurrentChild > ChildCount) CurrentChild = 0; + } + } +} \ No newline at end of file diff --git a/UdonSyncVideoPlayer.cs b/UdonSyncVideoPlayer.cs index f8df0d8..ed8a584 100644 --- a/UdonSyncVideoPlayer.cs +++ b/UdonSyncVideoPlayer.cs @@ -6,16 +6,28 @@ using VRC.SDK3.Components.Video; using VRC.SDK3.Video.Components.Base; using VRC.SDKBase; +using TMPro; +using VRC.SDK3.Video.Components.AVPro; +using VRC.SDK3.Video.Components; -namespace UdonVR.Takato +namespace UdonVR.Takato.VideoPlayer { public class UdonSyncVideoPlayer : UdonSharpBehaviour { - public BaseVRCVideoPlayer videoPlayer; + public VRCAVProVideoPlayer avProVideoPlayer; + public VRCUnityVideoPlayer unityVideoPlayer; + + [HideInInspector] public + BaseVRCVideoPlayer videoPlayer; public VRCUrl videoURL; public bool autoPlay; public VRCUrlInputField videoURLInputField; public MasterOnly MasterOnlyScript; + //public MeshRenderer aVProRenderTextureSource; + //public MeshRenderer screenMesh; + //public RenderTexture vRCUnityRenderTexture; + //private RenderTexture _AVProRenderTexture; + //public PanelController PanelController; public Text videoTime; public Slider videoTimeBar; @@ -24,6 +36,8 @@ public class UdonSyncVideoPlayer : UdonSharpBehaviour public float syncFrequency = 5; public float syncThreshold = 1; + + private float _lastSyncTime = 0; private float _delayTime; [UdonSynced] private float _videoStartNetworkTime = 0; @@ -42,18 +56,56 @@ public class UdonSyncVideoPlayer : UdonSharpBehaviour private bool _forcePlay = false; private int _retries; private int _deserialCount = 0; + private int ErrorCheck = 0; + private bool _newVideo = true; + private const int VRCUNITY_PLAYER_MODE = 1; + private const int AVPRO_PLAYER_MODE = 0; + [Range(0,1)] + public int defaultVideoPlayer = AVPRO_PLAYER_MODE; + [UdonSynced]private int _currentVideoMode = AVPRO_PLAYER_MODE; + private int _localVideoMode = AVPRO_PLAYER_MODE; private bool _debug = false; - public GameObject[] ErrorScreens; - private int ErrorCheck = 0; + public Image AVPro_fill; + public Image VRCUnity_fill; + + #region Auto resync Var + [Header("Resync")] + [Range(0.001f, 0.1f)] + public float ResyncTime = .1f; + public int autoResyncMinutes = 5; + public GameObject AutoResyncFill; + public InputField autoResyncRateInput; + public TextMeshProUGUI resyncText; + + private bool _resyncedVideo; + private bool _reloadedVideo; + private bool _forceResync; + [HideInInspector] + public bool autoResync; + private float _autoResyncRate; + private float _autoResyncTime; + #endregion + + public LoopToggle LT; private void Start() { //videoPlayer.Loop = false; - + //vRCUnityRenderTexture = (RenderTexture)screenMesh.sharedMaterial.GetTexture("_MainTex"); + if (defaultVideoPlayer == AVPRO_PLAYER_MODE) + { + SetVideoModeAvPro(); + } + else + { + SetVideoModeVRCUnity(); + } + + AutoResyncInit(); if (Networking.IsMaster && autoPlay) { _syncedURL = videoURL; @@ -70,9 +122,54 @@ private void Start() if (Networking.LocalPlayer.displayName == "Takato" || Networking.LocalPlayer.displayName == "Takato65" || Networking.LocalPlayer.displayName == "child of the beast") _debug = true; } + + if (Networking.IsMaster) LT.Init(); + } + public void ChangeVideoPlayerAvPro() + { + if (Networking.IsOwner(gameObject)) + { + videoPlayer.Stop(); + SetVideoModeAvPro(); + if (_ownerPlaying) + RetrySyncedVideo(); + } + } + public void ChangeVideoPlayerVRCUnity() + { + if (Networking.IsOwner(gameObject)) + { + videoPlayer.Stop(); + SetVideoModeVRCUnity(); + if (_ownerPlaying) + RetrySyncedVideo(); + } + } + void SetVideoModeAvPro() + { + Debug.Log("[UdonVR] Changing Player to AvPro"); + AVPro_fill.enabled = true; + VRCUnity_fill.enabled = false; + videoPlayer = avProVideoPlayer; + _currentVideoMode = AVPRO_PLAYER_MODE; + _localVideoMode = AVPRO_PLAYER_MODE; + + //screenMesh.sharedMaterial.SetTexture("_MainTex", aVProRenderTextureSource.sharedMaterial.GetTexture("_MainTex")); } - #region URL_Methods + void SetVideoModeVRCUnity() + { + Debug.Log("[UdonVR] Changing Player to VRCUnity"); + AVPro_fill.enabled = false; + VRCUnity_fill.enabled = true; + videoPlayer = unityVideoPlayer; + _currentVideoMode = VRCUNITY_PLAYER_MODE; + _localVideoMode = VRCUNITY_PLAYER_MODE; + + //screenMesh.sharedMaterial.SetTexture("_MainTex", vRCUnityRenderTexture); + } + + #region URL_Methods public void ChangeVideoUrlVRC(VRCUrl url) { @@ -91,11 +188,14 @@ public void ChangeVideoUrl() { //Debug.Log("[UdonSyncVideoPlayer] URL Changed Owner"); + //Set as new Video + _newVideo = true; + // Attempt to get a start time from YouTube links with t= or start= string urlStr = _syncedURL.Get(); _videoStartTime = 0f; - if (urlStr.Contains("youtu.be/") || (urlStr.Contains("youtube.com/watch"))) + if (urlStr.Contains("youtu.be/") || urlStr.Contains("youtube.com/watch")) { int startIndex; startIndex = urlStr.IndexOf("?t="); @@ -145,14 +245,13 @@ public void ChangeVideoUrl() } } - public void OnURLChanged() {//When the Owner changes the URL //Debug.Log("[UdonSyncVideoPlayer] URL Changed Start"); if (Networking.IsOwner(gameObject)) { //Debug.Log("[UdonSyncVideoPlayer] URL Changed Owner"); - if (videoURLInputField.GetUrl().Get() != "" && videoURLInputField.GetUrl() != _syncedURL) + if (videoURLInputField.GetUrl().Get().Trim() != "" && videoURLInputField.GetUrl() != _syncedURL) { _syncedURL = videoURLInputField.GetUrl(); ChangeVideoUrl(); @@ -160,7 +259,8 @@ public void OnURLChanged() } } - #endregion + #endregion URL_Methods + public bool EnableTimeBar() { return _paused && !_isTooLong; @@ -190,6 +290,7 @@ private void DebugLog() Debug.Log($"[UdonSyncVideoPlayer] videoPlayer.IsReady>> {videoPlayer.IsReady}"); Debug.Log($"[UdonSyncVideoPlayer] videoPlayer Owner>> {Networking.GetOwner(gameObject).displayName}"); Debug.Log($"[UdonSyncVideoPlayer] _forcePlay>> {_forcePlay}"); + //Debug.Log($"[UdonSyncVideoPlayer] {vRCUnityRenderTexture.}"); Debug.Log($"[UdonSyncVideoPlayer] =========================================="); } @@ -215,12 +316,27 @@ private void Update() SyncVideoIfTime(); } } - if (_ownerPlaying && !_ownerPaused && !_isTooLong) + if (_ownerPlaying && !_ownerPaused) { - //videoTime.text = string.Format("{0:N2}/{1:N2}",videoPlayer.GetTime(),videoPlayer.GetDuration()); - if (TimeSpan.MaxValue.TotalSeconds >= videoPlayer.GetTime()) - videoTimeBar.value = videoPlayer.GetTime(); + if (!_isTooLong) + { + //videoTime.text = string.Format("{0:N2}/{1:N2}",videoPlayer.GetTime(),videoPlayer.GetDuration()); + if (TimeSpan.MaxValue.TotalSeconds >= videoPlayer.GetTime()) + videoTimeBar.value = videoPlayer.GetTime(); + } + if (autoResync) + { + if (_autoResyncTime >= _autoResyncRate) + { + _autoResyncTime = 0; + _forceResync = true; + SyncVideo(); + } + else + _autoResyncTime += Time.deltaTime; + } } + if (_debug) { if (Input.GetKeyDown(KeyCode.P)) @@ -254,7 +370,7 @@ private void Update() public void UpdateDisplay() { - if (!_isTooLong) + if (!_isTooLong && _videoDuration != "Streaming!") videoTime.text = TimeSpan.FromSeconds(videoTimeBar.value).ToString(_timeFormat) + "/" + _videoDuration; else videoTime.text = _videoDuration; @@ -266,42 +382,66 @@ public void UpdateDisplay() } } - public void RetrySyncedVideo() - { - videoPlayer.LoadURL(_syncedURL); - SyncVideo(); - _loadedVideoURL = _syncedURL; - Debug.Log(string.Format("[UdonSyncVideoPlayer] Playing synced: {0}", _syncedURL)); + #region Syncing Methods - //Turn on forcePlay and set delayTime for repeat tries - _delayTime = Time.time + 7f; - _forcePlay = true; - _retries = 0; + public void ResyncReset() + { + Debug.LogWarning("[UdonVR] Playing synced: ResyncReset()"); + resyncText.text = "Resync"; + //PanelController.SetResyncText("Resync"); + _resyncedVideo = false; } + public void ReloadReset() + { + Debug.LogWarning("[UdonVR] Playing synced: ReloadReset()"); + resyncText.text = _resyncedVideo ? "Reload" : "Resync"; + //PanelController.SetResyncText(_resyncedVideo ? "Reload" : "Resync"); + _reloadedVideo = false; + } - - public void TakeOwner() + public void ResyncVideo() { - if (Networking.IsMaster) + Debug.LogWarning("[UdonVR] Playing synced: ResyncVideo"); + if (_resyncedVideo) { - DoTakeOwner(); + Debug.LogWarning("[UdonVR] Playing synced: _resyncedVideo"); + if (!_reloadedVideo) + { + Debug.LogWarning("[UdonVR] Playing synced: !_reloadedVideo"); + _reloadedVideo = true; + //PanelController.SetResyncText("Wait"); + resyncText.text = "Wait"; + + SendCustomEventDelayedSeconds("ReloadReset", 6f); + RetrySyncedVideo(); + } } - else if (MasterOnlyScript.syncedMasterOnly == false) + else { - DoTakeOwner(); + Debug.LogWarning("[UdonVR] Playing synced: !_resyncedVideo"); + _resyncedVideo = true; + + resyncText.text = _reloadedVideo ? "Wait" : "Reload"; + //PanelController.SetResyncText(_reloadedVideo ? "Wait" : "Reload"); + _forceResync = true; + SyncVideo(); + SendCustomEventDelayedSeconds("ResyncReset", 3f); } } - private void DoTakeOwner() + + public void RetrySyncedVideo() { - //Debug.Log("[UdonSyncVideoPlayer] TakeOWner Called!"); - if (!Networking.IsOwner(gameObject)) - { - //Debug.Log($"[UdonSyncVideoPlayer] Setting Owner to {Networking.LocalPlayer.displayName}"); - Networking.SetOwner(Networking.LocalPlayer, gameObject); - ownerText.text = Networking.LocalPlayer.displayName; + Debug.Log("[UdonVR] Playing synced: RetrySyncedVideo()"); + videoPlayer.LoadURL(_syncedURL); + SyncVideo(); + _loadedVideoURL = _syncedURL; + Debug.Log(string.Format("[UdonSyncVideoPlayer] Playing synced: {0}", _syncedURL)); - } + //Turn on forcePlay and set delayTime for repeat tries + _delayTime = Time.time + 7f; + _forcePlay = true; + _retries = 0; } public void SyncVideo() @@ -310,12 +450,21 @@ public void SyncVideo() float offsetTime; offsetTime = Mathf.Clamp(Convert.ToSingle(Networking.GetServerTimeInSeconds()) - _videoStartNetworkTime, 0, videoPlayer.GetDuration()); - if (Mathf.Abs(videoPlayer.GetTime() - offsetTime) > syncThreshold) + if (_forceResync) + offsetTime -= ResyncTime; + + if (_forceResync || Mathf.Abs(videoPlayer.GetTime() - offsetTime) > syncThreshold) {//Resync video time and log new value videoPlayer.SetTime(offsetTime); + _forceResync = false; //Debug.Log(string.Format("[UdonSyncVideoPlayer] Syncing Video to {0:N2}", offsetTime)); } } + public void ForceSyncVideo() + { + _forceResync = true; + SyncVideo(); + } public void SyncVideoIfTime() { @@ -332,6 +481,81 @@ public void SyncVideoIfTime() } } + #endregion Syncing Methods + + #region AutoResyncMethods + public void AutoResyncToggle() + { + autoResync = !autoResync; + AutoResyncFill.SetActive(autoResync); + + if (autoResync) + _autoResyncTime = 0; + + //Mock code + //PanelController.AutoResyncToggle(_autoResync); + } + + private void AutoResyncInit() + { + _autoResyncRate = autoResyncMinutes * 60; + autoResyncRateInput.text = autoResyncMinutes.ToString(); + //PanelController.AutoResyncRateInput(autoResyncMinutes); + } + public void AutoResyncSet(int value) + { + //int temp; + //int.TryParse(autoResyncRateInput.text, out temp); + + autoResyncMinutes = Mathf.Max(1, value); + _autoResyncRate = autoResyncMinutes * 60; + autoResyncRateInput.text = autoResyncMinutes.ToString(); + + //PanelController.AutoResyncRateInput(autoResyncMinutes); + } + public void AutoResyncDown() + { + autoResyncMinutes = Mathf.Max(1, autoResyncMinutes - 1); + _autoResyncRate = autoResyncMinutes * 60; + autoResyncRateInput.text = autoResyncMinutes.ToString(); + + //PanelController.AutoResyncRateInput(autoResyncMinutes); + } + public void AutoResyncUp() + { + //_autoResyncMinutes = Mathf.Max(1, _autoResyncMinutes - 1); + autoResyncMinutes++; + _autoResyncRate = autoResyncMinutes * 60; + autoResyncRateInput.text = autoResyncMinutes.ToString(); + + //PanelController.AutoResyncRateInput(autoResyncMinutes); + } + #endregion + + public void TakeOwner() + { + if (Networking.IsMaster) + { + DoTakeOwner(); + } + else if (MasterOnlyScript.syncedMasterOnly == false) + { + DoTakeOwner(); + } + } + + private void DoTakeOwner() + { + //Debug.Log("[UdonSyncVideoPlayer] TakeOWner Called!"); + if (!Networking.IsOwner(gameObject)) + { + //Debug.Log($"[UdonSyncVideoPlayer] Setting Owner to {Networking.LocalPlayer.displayName}"); + Networking.SetOwner(Networking.LocalPlayer, gameObject); + ownerText.text = Networking.LocalPlayer.displayName; + //PanelController.SetOwnerText(Networking.LocalPlayer.displayName); + } + } + private void SetUpTimeBar() { if (TimeSpan.MaxValue.TotalSeconds >= videoPlayer.GetDuration()) @@ -340,6 +564,7 @@ private void SetUpTimeBar() if (Networking.IsOwner(gameObject)) _isTooLong = false; videoTimeBar.maxValue = videoPlayer.GetDuration(); + //PanelController.SetVideoTimeBarMaxValue(videoPlayer.GetDuration()); if (timeSpan.TotalHours >= 1) _timeFormat = @"h\:mm\:ss"; @@ -356,14 +581,16 @@ private void SetUpTimeBar() if (Networking.IsOwner(gameObject)) _isTooLong = true; videoTimeBar.maxValue = 1; + //PanelController.SetVideoTimeBarMaxValue(1); _videoDuration = "Streaming!"; videoTimeBar.value = 1; + //PanelController.SetVideoTimeBarValue(1); + } } #region OnVideo_Overrides - public override void OnVideoLoop() { Debug.Log("[UdonSyncVideoPlayer] Video Looped"); @@ -408,8 +635,11 @@ public override void OnVideoStart() videoTimeBar.interactable = false; if (Networking.IsOwner(gameObject)) {//The Owner saves the start time and sets playing to true - if (!_ownerPaused) + if (!_ownerPaused && _newVideo) + { _videoStartNetworkTime = Convert.ToSingle(Networking.GetServerTimeInSeconds()) - _videoStartTime; + _newVideo = false; + } _ownerPlaying = true; _forcePlay = false; _ownerPaused = false; @@ -436,7 +666,7 @@ public override void OnVideoError(VideoError videoError) videoPlayer.Stop(); //Turn off forcePlay since video has error _forcePlay = false; - + if (ErrorCheck == 0) { if (ErrorScreens.Length == 5) @@ -444,13 +674,13 @@ public override void OnVideoError(VideoError videoError) ErrorCheck = 2; } else ErrorCheck = 1; - } - + if (ErrorCheck == 1) { Debug.Log(string.Format("[UdonSyncVideoPlayer] Video Error {0} >> {1}", videoError.ToString(), _syncedURL)); - } else if (ErrorCheck == 2) + } + else if (ErrorCheck == 2) { switch (videoError) { @@ -458,59 +688,79 @@ public override void OnVideoError(VideoError videoError) Debug.Log(string.Format("[UdonSyncVideoPlayer] Video Error {0} >> {1}", "[VP00]Unknown Error", _syncedURL)); if (ErrorScreens[0] != null) ErrorScreens[0].SetActive(true); break; + case VideoError.InvalidURL: Debug.Log(string.Format("[UdonSyncVideoPlayer] Video Error {0} >> {1}", "[VP01]InvalidURL Error", _syncedURL)); if (ErrorScreens[1] != null) ErrorScreens[1].SetActive(true); break; + case VideoError.AccessDenied: Debug.Log(string.Format("[UdonSyncVideoPlayer] Video Error {0} >> {1}", "[VP02]AccessDenied Error (Not on Whitelist)", _syncedURL)); if (ErrorScreens[2] != null) ErrorScreens[2].SetActive(true); break; + case VideoError.PlayerError: Debug.Log(string.Format("[UdonSyncVideoPlayer] Video Error {0} >> {1}", "[VP03]PlayerError Error", _syncedURL)); if (ErrorScreens[3] != null) ErrorScreens[3].SetActive(true); break; + case VideoError.RateLimited: Debug.Log(string.Format("[UdonSyncVideoPlayer] Video Error {0} >> {1}", "[VP04]RateLimit Error", _syncedURL)); if (ErrorScreens[4] != null) ErrorScreens[4].SetActive(true); break; + default: break; } } } - #endregion + #endregion OnVideo_Overrides + public override void OnPreSerialization() { _deserialCount = 0; } + public override void OnDeserialization() {//Load new video when _videoNumber is changed if (!Networking.IsOwner(gameObject)) { - if (_deserialCount < 10) { _deserialCount++; return; } - + if (_localVideoMode != _currentVideoMode) + { + videoPlayer.Stop(); + if (_currentVideoMode == AVPRO_PLAYER_MODE) + { + SetVideoModeAvPro(); + } + else + { + SetVideoModeVRCUnity(); + } + } if (_videoNumber != _loadedVideoNumber) { videoPlayer.Stop(); if (_loadedVideoURL != _syncedURL) { - videoPlayer.LoadURL(_syncedURL); - SyncVideo(); _loadedVideoNumber = _videoNumber; _loadedVideoURL = _syncedURL; - Debug.Log(string.Format("[UdonSyncVideoPlayer] Playing synced: {0}", _syncedURL)); - - //Turn on forcePlay and set delayTime for repeat tries - _delayTime = Time.time + 7f; - _forcePlay = true; - _retries = 0; + if (VRCUrl.Empty.Get() != _syncedURL.Get()) + { + videoPlayer.LoadURL(_syncedURL); + SyncVideo(); + Debug.Log(string.Format("[UdonSyncVideoPlayer] Playing synced: {0}", _syncedURL)); + + //Turn on forcePlay and set delayTime for repeat tries + _delayTime = Time.time + 7f; + _forcePlay = true; + _retries = 0; + } } else { @@ -533,11 +783,10 @@ public override void OnDeserialization() SyncVideo(); } } + } } - - public void StopVideo() { if (Networking.IsOwner(gameObject)) @@ -580,6 +829,7 @@ public void PauseVideo() { videoPlayer.Pause(); if (!_isTooLong) + //PanelController.VideoTimeBarInteractable(true); videoTimeBar.interactable = true; //_ownerPlaying = false; //_videoPausedNetworkTime = Convert.ToSingle(Networking.GetServerTimeInSeconds()); @@ -588,6 +838,7 @@ public void PauseVideo() else if (_videoStartNetworkTime != 0) { videoTimeBar.interactable = false; + //PanelController.VideoTimeBarInteractable(false); float videoCurrentTime = videoPlayer.GetTime(); diff --git a/VideoListManager.cs b/VideoListManager.cs index e0f21ad..04253d9 100644 --- a/VideoListManager.cs +++ b/VideoListManager.cs @@ -1,6 +1,6 @@  using UdonSharp; -using UdonVR.Takato; +using UdonVR.Takato.VideoPlayer; using UnityEngine; using UnityEngine.UI; using VRC.SDKBase;