Ejemplo n.º 1
0
        public void Play(object whatStartedPlayingThis = null)
        {
            WhatStartedPlayingThis = whatStartedPlayingThis;

            foreach (var namedEvent in namedEvents)
            {
                if (namedActions.ContainsKey(namedEvent.Name))
                {
                    var action = namedActions[namedEvent.Name];

                    var instruction = new DelegateInstruction(action);
                    instruction.TimeToExecute = TimeManager.CurrentTime + namedEvent.Time;
                    instruction.Target        = this;
                    InstructionManager.Instructions.Add(instruction);
                }
            }

            foreach (var instruction in getInstructionsFunc(this))
            {
                InstructionManager.Instructions.Add(instruction);
            }

            {
                Action endReachedAction = () => EndReached?.Invoke();
                var    endInstruction   = new DelegateInstruction(endReachedAction);
                endInstruction.TimeToExecute = TimeManager.CurrentTime + this.Length;
                endInstruction.Target        = this;
                InstructionManager.Instructions.Add(endInstruction);
            }
        }
Ejemplo n.º 2
0
 void VlcMediaPlayer_EndReached(object sender, Meta.Vlc.ObjectEventArgs <Meta.Vlc.Interop.Media.MediaState> e)
 {
     state = MovieMediaState.Ended;
     if (EndReached != null)
     {
         EndReached.Invoke(this, EventArgs.Empty);
     }
 }
        public bool UpdateTimeAndEvaluate()
        {
            var playableGraph = Director.playableGraph;

            if (!playableGraph.IsValid() || !playableGraph.IsPlaying())
            {
                return(false);
            }

            var loop            = Director.extrapolationMode == DirectorWrapMode.Loop && !IsSyncing;
            var newTime         = Director.time + MarsTime.TimeStep;
            var reachedDuration = newTime >= m_Duration;

            if (reachedDuration && loop)
            {
                foreach (var provider in m_RecordedDataProviders)
                {
                    provider.ClearData();
                }

                newTime            -= m_Duration;
                m_NotificationsSent = 0;
            }

            var reachedPauseTime = newTime >= PlaybackPauseTime;

            if (reachedPauseTime)
            {
                newTime = PlaybackPauseTime;
            }

            SetTime(newTime);
            Evaluate();
            for (var i = m_NotificationsSent; i < m_TimelineNotifications.Count; i++)
            {
                var notificationData = m_TimelineNotifications[i];
                if (notificationData.Time > newTime)
                {
                    break;
                }

                SendNotification(notificationData);
            }

            if (reachedPauseTime)
            {
                Director.Pause();
            }

            if (reachedDuration)
            {
                EndReached?.Invoke();
            }

            return(true);
        }
Ejemplo n.º 4
0
 private void Update()
 {
     if (isMoving)
     {
         moveLerp            += targetObjectManager.targetSpeed * Time.deltaTime;
         transform.position   = Vector3.Lerp(moveStart, moveEnd, moveLerp);
         transform.rotation  *= Quaternion.AngleAxis(rotationSpeed * Time.deltaTime, Vector3.forward);
         transform.localScale = Vector3.one * sizeOverLifetime.Evaluate(moveLerp);
         if (moveLerp >= 1f)
         {
             isMoving = false;
             if (EndReached != null)
             {
                 EndReached.Invoke(this);
             }
         }
     }
 }
Ejemplo n.º 5
0
        private void UpdateScene()
        {
            var animation = _editor.GetCurrentAnimation();

            if (animation.IsLoop != _previousIsLoop)
            {
                SetPlayCursorToCurrentFrame();
                _previousIsLoop = animation.IsLoop;
            }
            var animationFrame = CalculateCurrentFrame();

            _editor.ApplyFrameToScene((float)animationFrame, _isFirstFrame);
            _isFirstFrame = false;

            var animationFrameInt = (int)animationFrame;

            SetDopesheetTimeCursor(animationFrameInt);

            if (!animation.IsLoop && animationFrameInt == animation.EndFrame)
            {
                EndReached?.Invoke();
            }
        }
Ejemplo n.º 6
0
 private void VlcMediaPlayer_OnEndReached(object sender, VlcMediaPlayerEndReachedEventArgs e)
 {
     EndReached?.Invoke(this, new EndReachedEventArgs());
 }
Ejemplo n.º 7
0
        private async void ListenForMediaChanges(CancellationToken token)
        {
            try
            {
                _logger.LogInfo($"{nameof(ListenForMediaChanges)}: Starting the media changes loop");
                await ListenMediaChangesSemaphoreSlim.WaitAsync(token);

                await Task.Run(async() =>
                {
                    bool checkMediaStatus = true;
                    while (checkMediaStatus || !token.IsCancellationRequested)
                    {
                        await Task.Delay(GetMediaStatusDelay, token);

                        var mediaStatus = await _mediaChannel.GetStatusAsync(_sender);
                        if (token.IsCancellationRequested)
                        {
                            break;
                        }

                        if (mediaStatus is null)
                        {
                            bool contentIsBeingPlayed = !string.IsNullOrEmpty(CurrentContentId);
                            IsPlaying        = false;
                            checkMediaStatus = false;
                            _logger.LogInfo(
                                $"{nameof(ListenForMediaChanges)}: Media is null, content was being played = {contentIsBeingPlayed}, " +
                                $"player was paused = {IsPaused} and we are connected = {_sender.IsConnected}. " +
                                $"CurrentContentId = {CurrentContentId}");
                            CancelAndSetListenerToken(false);

                            //Only call the end reached if we were playing something, the player was not paused and we are connected
                            if (contentIsBeingPlayed && !IsPaused && _sender.IsConnected)
                            {
                                EndReached?.Invoke(this, EventArgs.Empty);
                            }
                            IsPaused = false;
                            break;
                        }

                        ElapsedSeconds = mediaStatus.CurrentTime + _seekedSeconds;
                        if (mediaStatus.PlayerState == PlayerState.Paused)
                        {
                            IsPaused  = true;
                            IsPlaying = false;
                            Paused?.Invoke(this, EventArgs.Empty);
                            continue;
                        }
                        IsPlaying = true;
                        IsPaused  = false;
                        TriggerTimeEvents();
                        //If CurrentMediaDuration  <= 0, that means that a live streaming is being played
                        if (CurrentMediaDuration > 0 && Math.Round(ElapsedSeconds, 4) >= Math.Round(CurrentMediaDuration, 4))
                        {
                            _logger.LogInfo(
                                $"{nameof(ListenForMediaChanges)}: End reached because the " +
                                $"ElapsedSeconds = {ElapsedSeconds} is greater / equal to " +
                                $"CurrentMediaDuration = {CurrentMediaDuration}. CurrentContentId = {CurrentContentId}");
                            IsPlaying = false;
                            CancelAndSetListenerToken(false);
                            EndReached?.Invoke(this, EventArgs.Empty);
                            break;
                        }
                    }
                }, token).ConfigureAwait(false);
            }
            catch (Exception e)
            {
                if (e is TaskCanceledException || e is OperationCanceledException)
                {
                    return;
                }
                _logger.LogError($"{nameof(ListenForMediaChanges)}: Unknown error occurred", e);
            }
            finally
            {
                _logger.LogInfo($"{nameof(ListenForMediaChanges)}: Media changes loop completed");
                if (ListenMediaChangesSemaphoreSlim.CurrentCount == 0)
                {
                    ListenMediaChangesSemaphoreSlim.Release();
                }
            }
        }
Ejemplo n.º 8
0
    protected virtual void OnEndReached()
    {
        StopMovement();

        EndReached?.Invoke();
    }
Ejemplo n.º 9
0
        public VLCMediaPlayer(InputData inputData, ILogger <VLCMediaPlayer> logger)
        {
            this.logger = logger;
            Core.Initialize();
            localFileStreamClient = new Client();
            if (inputData.AttachDebugger)
            {
                vlcArguments.Add("--verbose=2");
            }
            else
            {
                vlcArguments.Add("--verbose=0");
            }

            library      = new LibVLC(vlcArguments.ToArray());
            library.Log += Library_Log;
            mediaPlayer  = new LibVLCSharp.Shared.MediaPlayer(library)
            {
                Hwnd                   = new IntPtr(inputData.Handle),
                EnableKeyInput         = false,
                EnableMouseInput       = false,
                EnableHardwareDecoding = true,
            };
            mediaPlayer.PositionChanged += MediaPlayer_PositionChanged;
            mediaPlayer.EndReached      += (sender, args) =>
            {
                EndReached?.Invoke(this, args);
            };
            mediaPlayer.TimeChanged += (sender, args) =>
            {
                time = args.Time;
                TimeChanged?.Invoke(this, args.Time);

                if (aspectRationSet || mediaPlayer.VideoTrack == -1)
                {
                    return;
                }

                aspectRationSet = true;

                uint  x           = 0;
                uint  y           = 0;
                float aspectRatio = 1;

                if (!mediaPlayer.Size(0, ref x, ref y))
                {
                    return;
                }

                var videoTrack  = mediaPlayer.Media.Tracks.FirstOrDefault(track => track.TrackType == TrackType.Video);
                var orientation = videoTrack.Data.Video.Orientation;

                if (IsFlipped(orientation))
                {
                    aspectRatio = (float)y / x;
                }
                else
                {
                    aspectRatio = (float)x / y;
                }

                if (videoTrack.Data.Video.SarDen != 0)
                {
                    aspectRatio *= (float)videoTrack.Data.Video.SarNum / videoTrack.Data.Video.SarDen;
                }

                VideoInfoChanged?.Invoke(this, new VideoInfo
                {
                    VideoOrientation = orientation.ToString(),
                    AspectRatio      = aspectRatio
                });
            };

            mediaPlayer.LengthChanged += (sender, args) => { if (args.Length > 0)
                                                             {
                                                                 LengthChanged?.Invoke(this, args);
                                                             }
            };
            mediaPlayer.Playing       += (sender, args) => Playing?.Invoke(this, args);
            mediaPlayer.Paused        += (sender, args) => Paused?.Invoke(this, args);
            mediaPlayer.VolumeChanged += (sender, args) => VolumeChanged?.Invoke(this, args);
            mediaPlayer.Unmuted       += (sender, args) => Unmuted?.Invoke(this, args);
            mediaPlayer.Muted         += (sender, args) => Muted?.Invoke(this, args);
        }