//        public void SpeedChange(float speed)
//        {
//            if (!playbackSpeed.enabled)
//                playbackSpeed.enabled = true;
//
//            playbackSpeed.SetFloat("PlaybackSpeed", speed);
//            playbackSpeed.SetBool("IsChange", true);
//        }

        public void OnURLChanged()
        {
            if (String.IsNullOrEmpty(url.GetUrl().Get()))
            {
                return;
            }

            if (masterOnly && !Networking.LocalPlayer.isMaster)
            {
                return;
            }

            Debug.Log($"[KineL] Start process");
            ChangeOwner(Networking.LocalPlayer);

            if (list != null)
            {
                if (list.autoPlay)
                {
                    list.SendCustomNetworkEvent(NetworkEventTarget.All, nameof(KinelPlaylist.AutoPlayDisable));
                }
            }


            syncedURL = url.GetUrl();
            PlayVideo(syncedURL);
            RequestSerialization();
        }
Exemplo n.º 2
0
 public void PowerOnLive()
 {
     DebugLog($"Trigger a live player power-on event.");
     TakeOwnership();
     _urlSync = VRCUrl.Empty;
     SendCustomNetworkEvent(NetworkEventTarget.All, nameof(OnPowerOnLive));
 }
Exemplo n.º 3
0
        void _PlayVideo(VRCUrl url)
        {
            _pendingPlayTime = 0;
            DebugLog("Play video " + url);
            bool isOwner = Networking.IsOwner(gameObject);

            if (!isOwner && !_CanTakeControl())
            {
                return;
            }

            if (!_IsUrlValid(url))
            {
                return;
            }

            if (!isOwner)
            {
                Networking.SetOwner(Networking.LocalPlayer, gameObject);
            }

            _syncUrl           = url;
            _syncVideoNumber  += isOwner ? 1 : 2;
            _loadedVideoNumber = _syncVideoNumber;
            _syncOwnerPlaying  = false;

            _syncVideoStartNetworkTime = float.MaxValue;
            RequestSerialization();

            _videoTargetTime = _ParseTimeFromUrl(url.Get());

            _StartVideoLoad();
        }
Exemplo n.º 4
0
        public void _StopVideo()
        {
            DebugLog("Stop video");

            if (seekableSource)
            {
                _lastVideoPosition = _currentPlayer.GetTime();
            }

            localPlayerState = PLAYER_STATE_STOPPED;

            _currentPlayer.Stop();
            _videoTargetTime = 0;
            _pendingPlayTime = 0;
            _pendingLoadTime = 0;
            _playStartTime   = 0;

            if (Networking.IsOwner(gameObject))
            {
                _syncVideoStartNetworkTime = 0;
                _syncOwnerPlaying          = false;
                _syncUrl = VRCUrl.Empty;
                RequestSerialization();
            }
        }
Exemplo n.º 5
0
        void StartVideoLoad(VRCUrl url)
        {
            if (Time.time < _delayStartLoad)
            {
                return;
            }

            if (url != null)
            {
                string urlStr = url.Get();

                // RTSPT sources (and maybe others!?) trigger a spontaneous OnVideoEnd event at video start
                if (currentPlayerMode == PLAYER_MODE_STREAM && urlStr.Contains("rtspt://"))
                {
                    _rtsptSource = true;
                    Debug.Log("[USharpVideo] Detected RTSPT source");
                }
                else
                {
                    _rtsptSource = false;
                }
            }

            Debug.Log("[USharpVideo] Started video load");
            _statusStr = "Loading video...";
            SetStatusText(_statusStr);
            _delayStartLoad     = 0f;
            _loadingVideo       = true;
            _currentLoadingTime = 0f;
            _currentRetryCount  = 0;
            _currentPlayer.Stop();
            _currentPlayer.LoadURL(url);
        }
Exemplo n.º 6
0
    /// <summary>
    /// Changes a normal URI to an array of accepted VRCUrl objects
    /// </summary>
    /// <example>
    ///     Input: user/get/foo
    ///     Output: { "http://localhost/user", "http://localhost/get", "http://localhost/f", "http://localhost/o", "http://localhost/o" }
    /// </example>
    /// <param name="alphabet">VRCUrl array</param>
    /// <param name="input">the string we want to convert</param>
    /// <param name="delimiter">how is the URI delimited? are we using / or ?</param>
    /// <returns></returns>
    private VRCUrl[] StringToPlaylist(VRCUrl[] alphabet, string input, char delimiter = '/')
    {
        if (!input.EndsWith("]"))
        {
            input += "]";
        }

        VRCUrl[] rtrn       = new VRCUrl[0] {
        };
        VRCUrl delimiterUrl = GetUrlRelatingToInput(alphabet, delimiter.ToString());

        string[] sections = input.Split(delimiter);

        for (int i = 0; i < sections.Length; i++)
        {
            string section = sections[i];
            VRCUrl link    = GetUrlRelatingToInput(alphabet, section);

            if (link != null) // section exists
            {
                if (rtrn.Length == 0)
                {
                    rtrn = new VRCUrl[2] {
                        link, delimiterUrl
                    };
                }
                else
                {
                    VRCUrl[] resized = new VRCUrl[rtrn.Length + 2]; // 2, we need 1 for the delimiter
                    Array.Copy(rtrn, 0, resized, 0, rtrn.Length);   // simple copy
                    resized[resized.Length - 1] = delimiterUrl;     // end with the delimiter
                    resized[resized.Length - 2] = link;
                    rtrn = resized;
                }
            }
            else // no known section exists we gotta iterate through the characters
            {
                int      rtrnLength = rtrn.Length;
                VRCUrl[] resized    = new VRCUrl[rtrn.Length + section.Length + (i == sections.Length - 1 ? 0 : 1)]; // if we're at the last section we don't need an additional index for a delimiter

                for (int k = 0; k < section.Length; k++)
                {
                    link = GetUrlRelatingToInput(alphabet, section.Substring(k, 1)); // would've just wanted to use the indexer on the string here but Udon doesn't allow indexers on strings what?
                    Array.Copy(rtrn, 0, resized, 0, rtrn.Length);
                    resized[rtrnLength + k] = link;
                    rtrn = resized;
                }

                // if we're not at the last section we add a delimiter
                if (i != sections.Length - 1)
                {
                    rtrn[rtrn.Length - 1] = delimiterUrl;
                }
            }
        }

        return(rtrn);
    }
Exemplo n.º 7
0
    public VRCUrl[] Concate(VRCUrl[] first, VRCUrl[] second)
    {
        VRCUrl[] concated = new VRCUrl[first.Length + second.Length];

        first.CopyTo(concated, 0);
        second.CopyTo(concated, first.Length);

        return(concated);
    }
Exemplo n.º 8
0
 void StartVideoLoad(VRCUrl url)
 {
     Debug.Log("[USharpVideo] Started video load");
     _statusStr = "Loading video...";
     SetStatusText(_statusStr);
     _loadingVideo       = true;
     _currentLoadingTime = 0f;
     _currentRetryCount  = 0;
     _currentPlayer.LoadURL(url);
 }
Exemplo n.º 9
0
        public void _ChangeUrl(VRCUrl url)
        {
            if (_syncLocked && !_CanTakeControl())
            {
                return;
            }

            _PlayVideo(url);

            _queuedUrl = VRCUrl.Empty;
        }
Exemplo n.º 10
0
 public void OnURLChanged()
 {
     if (string.IsNullOrEmpty(_addressInput.GetUrl().Get()))
     {
         return;
     }
     DebugLog($"The URL has changed to `{_addressInput.GetUrl().Get()}`. Next serial is {_serialSync + 1}.");
     _urlSync = _addressInput.GetUrl();
     _serialSync++;
     SetOffsetTime(GetOffsetTime(_urlSync.Get()));
     LoadURL(_urlSync, _serialSync);
 }
Exemplo n.º 11
0
        public void _HandleUrlInput()
        {
            if (!Utilities.IsValid(videoPlayer))
            {
                return;
            }

            pendingFromLoadOverride = loadActive;
            pendingSubmit           = urlInput.GetUrl();

            SendCustomEventDelayedSeconds("_HandleUrlInputDelay", 0.5f);
        }
Exemplo n.º 12
0
        // Stop video button
        public void StopVideo()
        {
            if (!Networking.IsOwner(gameObject))
            {
                return;
            }

            _videoStartNetworkTime = 0f;
            _ownerPlaying          = false;
            _currentPlayer.Stop();
            _syncedURL = VRCUrl.Empty;
        }
 public void ResetGlobal()
 {
     SendCustomNetworkEvent(NetworkEventTarget.All, nameof(ResetLocal));
     ChangeOwner(Networking.LocalPlayer);
     url.SetUrl(VRCUrl.Empty);
     syncedURL            = VRCUrl.Empty;
     isPlaying            = false;
     isPause              = false;
     videoStartGlobalTime = 0;
     pausedTime           = 0;
     RequestSerialization();
 }
Exemplo n.º 14
0
        public void _UpdateQueuedUrl(VRCUrl url)
        {
            if (_syncLocked && !_CanTakeControl())
            {
                return;
            }
            if (!Networking.IsOwner(gameObject))
            {
                Networking.SetOwner(Networking.LocalPlayer, gameObject);
            }

            _queuedUrl = url;
        }
Exemplo n.º 15
0
        public void _HandleUrlInputChange()
        {
            if (!Utilities.IsValid(videoPlayer))
            {
                return;
            }

            VRCUrl url = urlInput.GetUrl();

            if (url.Get().Length > 0)
            {
                videoPlayer._UpdateQueuedUrl(urlInput.GetUrl());
            }
        }
 // Event called locally by any person who enters a new URL
 public void _u_ChannelEntered()
 {
     debug._u_Log("[YoutubeVideoInfo] _u_ChannelEntered");
     // Always sync URL across all players' clients, even if it
     // isn't a valid youtube video.  It would be better if there
     // were deserialization callbacks on the main video player to get
     // its synced url instead.
     requestingOwnership = true;
     Networking.SetOwner(Networking.LocalPlayer, gameObject);
     syncedURL = urlField.GetUrl();
     syncedURLserializations++;
     RequestSerialization();
     _u_Resync();
 }
Exemplo n.º 17
0
 void LoadURL(VRCUrl url, int serial)
 {
     if (!_player)
     {
         return;
     }
     DebugLog($"Load the video with the URL `{url.Get()}` and set the serial to {serial}.");
     _status           = _status & ~_status_stop | _status_fetch;
     _url              = url;
     _serial           = serial;
     _messageText.text = $"Loading";
     _player.Stop();
     _player.LoadURL(url);
     ValidateView();
 }
Exemplo n.º 18
0
        // Stop video button
        void StopVideo()
        {
            if (!Networking.IsOwner(gameObject))
            {
                return;
            }

            _videoStartNetworkTime = 0f;
            _ownerPlaying          = false;
            _currentPlayer.Stop();
            _syncedURL            = VRCUrl.Empty;
            _locallyPaused        = _ownerPaused = false;
            _draggingSlider       = false;
            _videoTargetStartTime = 0f;
        }
Exemplo n.º 19
0
        bool _IsUrlValid(VRCUrl url)
        {
            if (!Utilities.IsValid(url))
            {
                return(false);
            }

            string urlStr = url.Get();

            if (urlStr == null || urlStr == "")
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 20
0
    public void OnURLChanged()
    {
        VRCUrl url = inputField.GetUrl();

        if (url != null)
        {
            Debug.Log("OnURLChanged url: " + url.ToString());
        }
        if (!Networking.IsOwner(gameObject))
        {
            Debug.Log("Take ownership");
            Networking.SetOwner(Networking.LocalPlayer, gameObject);
        }
        _syncedURL = url;
        unityVideoPlayer.LoadURL(url);
    }
Exemplo n.º 21
0
        public void _HandleUrlInputDelay()
        {
            VRCUrl url = urlInput.GetUrl();

            urlInput.SetUrl(VRCUrl.Empty);

            // Hack to get around Unity always firing OnEndEdit event for submit and lost focus
            // If loading override was on, but it's off immediately after submit, assume user closed override
            // instead of submitting.  Half second delay is a crude defense against a UI race.
            if (pendingFromLoadOverride && !loadActive)
            {
                return;
            }

            videoPlayer._ChangeUrl(url);
            loadActive = false;
        }
        public bool PlayVideo(VRCUrl playURL)
        {
            if (!IsValidURL(playURL.Get()))
            {
                OnVideoError(VideoError.InvalidURL);
                Debug.LogError($"[KineL] Loading Error: URL invalid");
                return(false);
            }

            if (videoPlayer.IsPlaying)
            {
                videoPlayer.Stop();
            }

            if (isPause)
            {
                isPauseLocal = false;
            }

            inputFieldLoadMessage.SetActive(true);
            videoLoadErrorController.hide();

            if (Networking.IsOwner(Networking.LocalPlayer, this.gameObject))
            {
                globalVideoID++;
                localVideoID = globalVideoID;
                isPause      = false;
                isPlaying    = true;
                syncedURL    = playURL;
                url.SetUrl(VRCUrl.Empty);
                RequestSerialization();
                Debug.Log($"[KineL] Loading ... : {syncedURL}");
                SendCustomEventDelayedSeconds(nameof(OwnerPlayVideo), 1.5f);

                return(true);
            }

            Debug.Log($"[KineL] Loading ... : {syncedURL}");
            videoPlayer.LoadURL(playURL);
            isPauseLocal = false;
            return(true);
        }
Exemplo n.º 23
0
        public void HandleURLInput()
        {
            if (!Networking.IsOwner(gameObject))
            {
                return;
            }

            _syncedURL = inputField.GetUrl();
            _videoNumber++;

            _loadedVideoNumber = _videoNumber;

            _currentPlayer.Stop();
            _currentPlayer.LoadURL(_syncedURL);
            _ownerPlaying = false;

            _videoStartNetworkTime = float.MaxValue;

            Debug.Log("Video URL Changed to " + _syncedURL);
        }
        public override void OnVideoEnd()
        {
            if (Networking.IsOwner(Networking.LocalPlayer, this.gameObject))
            {
                videoStartGlobalTime = (float)Networking.GetServerTimeInSeconds();
                isPlaying            = false;
                videoPlayer.Stop();
                syncedURL = VRCUrl.Empty;
                isPause   = false;
                RequestSerialization();
            }

            if (Networking.LocalPlayer.isMaster)
            {
                if (list != null)
                {
                    if (list.autoPlay)
                    {
                        list.PlayNextVideo();
                    }
                }
            }
        }
Exemplo n.º 25
0
 public void _PlayQueuedUrl()
 {
     _PlayVideo(_queuedUrl);
     _queuedUrl = VRCUrl.Empty;
 }
Exemplo n.º 26
0
        void PlayVideo(VRCUrl url, bool disablePlaylist)
        {
            bool isOwner = Networking.IsOwner(gameObject);

            if (!isOwner && !Networking.IsMaster && _masterOnly)
            {
                return;
            }

            if (_syncedURL != null && url.Get() == "")
            {
                return;
            }

            if (!isOwner)
            {
                Networking.SetOwner(Networking.LocalPlayer, gameObject);
            }

            if (disablePlaylist)
            {
                // -1 means we have stopped using the playlist since we had manual input
                _nextPlaylistIndex = -1;
            }

            StopVideo();

            _syncedURL = url;
            inputField.SetUrl(VRCUrl.Empty);

            if (isOwner)
            {
                _videoNumber++;
            }
            else // Add two to avoid having conflicts where the old owner increases the count
            {
                _videoNumber += 2;
            }

            _loadedVideoNumber = _videoNumber;
            StartVideoLoad(_syncedURL);
            _currentPlayer.Stop();
            _ownerPlaying  = false;
            _locallyPaused = _ownerPaused = false;

            _videoStartNetworkTime = float.MaxValue;

            if (Networking.IsOwner(gameObject))
            {
                // Attempt to parse out a start time from YouTube links with t= or start=
                string urlStr = url.Get();

                if (currentPlayerMode != PLAYER_MODE_STREAM &&
                    (urlStr.Contains("youtube.com/watch") ||
                     urlStr.Contains("youtu.be/")))
                {
                    int tIndex = -1;

                    tIndex = urlStr.IndexOf("?t=");

                    if (tIndex == -1)
                    {
                        tIndex = urlStr.IndexOf("&t=");
                    }
                    if (tIndex == -1)
                    {
                        tIndex = urlStr.IndexOf("?start=");
                    }
                    if (tIndex == -1)
                    {
                        tIndex = urlStr.IndexOf("&start=");
                    }

                    if (tIndex != -1)
                    {
                        char[] urlArr = urlStr.ToCharArray();
                        int    numIdx = urlStr.IndexOf('=', tIndex) + 1;

                        string intStr = "";

                        while (numIdx < urlArr.Length)
                        {
                            char currentChar = urlArr[numIdx];
                            if (!char.IsNumber(currentChar))
                            {
                                break;
                            }

                            intStr += currentChar;

                            ++numIdx;
                        }

                        if (intStr.Length > 0)
                        {
                            int secondsCount = 0;
                            if (int.TryParse(intStr, out secondsCount))
                            {
                                _videoTargetStartTime = secondsCount;
                            }
                            else
                            {
                                _videoTargetStartTime = 0f;
                            }
                        }
                        else
                        {
                            _videoTargetStartTime = 0f;
                        }
                    }
                    else
                    {
                        _videoTargetStartTime = 0f;
                    }
                }
                else
                {
                    _videoTargetStartTime = 0f;
                }
            }
            else
            {
                _videoTargetStartTime = 0f;
            }

            Debug.Log("[USharpVideo] Video URL Changed to " + _syncedURL);
        }
Exemplo n.º 27
0
 public void StopVideo()
 {
     unityVideoPlayer.Stop();
     currentUrl = null;
 }
Exemplo n.º 28
0
 public void PlayVideo(VRCUrl url)
 {
     StopVideo();
     currentUrl = url;
     unityVideoPlayer.LoadURL(url);
 }
Exemplo n.º 29
0
        public override void OnDeserialization()
        {
            // Load new video when _videoNumber is changed
            if (Networking.IsOwner(gameObject))
            {
                return;
            }

            if (_needsOwnerTransition)
            {
                _masterOnly = _masterOnlyLocal;
                Debug.Log("[USharpVideo] Deserialize needs transition -> " + _masterOnly);
            }
            else
            {
                _masterOnlyLocal = _masterOnly;
                masterLockedIcon.SetActive(_masterOnly && controlMode != CONTROL_MODE_ANY);
                masterUnlockedIcon.SetActive(!_masterOnly || controlMode == CONTROL_MODE_ANY);
            }

            playIcon.SetActive(_ownerPaused);
            pauseStopIcon.SetActive(!_ownerPaused);
            playlistNormalIcon.SetActive(_playlistMode == PLAYLIST_MODE_NORMAL);
            repeatIcon.SetActive(_playlistMode == PLAYLIST_MODE_REPEAT);

            // Needed to prevent "rewinding" behaviour of Udon synced strings/VRCUrl's where, when switching ownership the string will be populated with the second to last value locally observed.
            if (_deserializeCounter < 10)
            {
                _deserializeCounter++;
                return;
            }

            if (_localPlayerMode != currentPlayerMode)
            {
                ChangePlayerMode();
            }

            if (!_ownerPaused && _locallyPaused)
            {
                Debug.Log("[USharpVideo] Play");
                _currentPlayer.Play();
                _locallyPaused = false;
            }

            if (_videoNumber == _loadedVideoNumber)
            {
                return;
            }

            if (_localUrl != null && _syncedURL != null && _syncedURL.Get() == _localUrl.Get())
            {
                if (_currentPlayer.IsPlaying && _streamBypassOwner && currentPlayerMode == PLAYER_MODE_STREAM)
                {
                    _loadedVideoNumber = _videoNumber;
                    return;
                }
            }

            _localUrl = _syncedURL;

            _currentPlayer.Stop();
            StartVideoLoad(_syncedURL);

            SyncVideo();

            _loadedVideoNumber = _videoNumber;

            Debug.Log("[USharpVideo] Playing synced " + _syncedURL);
        }