public override void Start() { base.Start(); //Register Events OnYoutubeUrlAreReady.AddListener(UrlReadyToUse); OnVideoFinished.AddListener(OnVideoPlayerFinished); OnVideoReadyToStart.AddListener(OnVideoLoaded); }
///<summary>Called when the video end.</summary> public void OnVideoPlayerFinished() { if (!finishedCalled) { finishedCalled = true; StartCoroutine(PreventFinishToBeCalledTwoTimes()); if (!loadYoutubeUrlsOnly) { if (videoPlayer.isPrepared) { if (debug) { Debug.Log("Finished"); } if (videoPlayer.isLooping) { videoPlayer.time = 0; videoPlayer.frame = 0; audioPlayer.time = 0; audioPlayer.frame = 0; videoPlayer.Play(); if (!noAudioAtacched) { audioPlayer.Play(); } } CancelInvoke("CheckIfIsSync"); OnVideoFinished.Invoke(); if (customPlaylist && autoPlayNextVideo) { Debug.Log("Calling next video of playlist"); CallNextUrl(); } } } else { if (playUsingInternalDevicePlayer) { CancelInvoke("CheckIfIsSync"); OnVideoFinished.Invoke(); } } } }
private void Update() { //Debug.Log("Delta: " + Time.deltaTime + ", Time: " + Time.time + ", Plugin Time: " + GetCurrentPlayingTime()); if (_playerInstance != IntPtr.Zero) { if (processVideoTime == true) { if (_playState == PlayState.PLAYING) // && IsPaused() == false) { // If video has reached its end and loop is true, reset target time: if (_loopVideo == true) { float curVideoPlayTime = GetCurrentPlayTime(); if (curVideoPlayTime < _lastVideoPlayTime) { _targetTime = 0f; } _lastVideoPlayTime = curVideoPlayTime; } UpdateVideoTargetTime(Time.deltaTime * 1000f); // Set target time in ms: _targetTime = Mathf.Min(GetCurrentPlayTime() + 1000f * _maxCatchUpFrames / _framerate, _targetTime); SetTargetPlayTime(_targetTime); } } if (_playState == PlayState.PLAYING) // && IsPaused() == false) { if (IsFinished() == true) { _playState = PlayState.STOPPED; Debug.Log("Video finished"); if (OnVideoFinished != null) { foreach (VideoFinishedDelegate VideoFinished in OnVideoFinished.GetInvocationList()) { try { VideoFinished(this); } catch (Exception ex) { Debug.LogException(ex); } } } } if (_shallPause == true) { if (GetCurrentPlayTime() >= _shallPauseAt) { _shallPause = false; Pause(); } } } else if (_playState == PlayState.PAUSED) { if (GetCurrentPlayTime() < _shallPauseAt) { _shallPause = true; Resume(); } } _command.IssuePluginEventAndData(GetRenderEventFunc(), 0, _playerInstance); Graphics.ExecuteCommandBuffer(_command); _command.Clear(); } }