//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    //	* New Methods: Play Through Rhythm List
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    public void PlayThroughRhythmList(Playlist ePlaylist)
    {
        // Stop Player Input
        //ButtonManager.ToggleAllButtons(false);
        TambourineShakeDetector.CheckForShake = false;

        // Setup Rhythm List Variables (These will be used to keep track of where we are in the playlist)
        PlaybackInfo[] aCurrentPlaylist = GetPlaylist(ePlaylist);
        int            iLoopCount       = m_arTrackSoundInfo[(int)ePlaylist].loopCount;

        // Begin Playback
        m_bIsPlaying = true;


        // Create playlist. Making sure to loop through more than once if the rhythm requires looping
        m_lPlaylist.Clear();
        for (int i = 0; i < iLoopCount; ++i)
        {
            for (int j = 0; j < aCurrentPlaylist.Length; ++j)
            {
                // Put all sound into list. If on second loop; multiply start and end times by the last note finish time. This will push notes BACK after the last note, creating a loop
                PlaybackInfo pbi = new PlaybackInfo();
                pbi.type      = aCurrentPlaylist[j].type;
                pbi.startTime = m_fStartDelayTime + aCurrentPlaylist[j].startTime + aCurrentPlaylist[aCurrentPlaylist.Length - 1].endTime * i;
                pbi.endTime   = m_fStartDelayTime + aCurrentPlaylist[j].endTime + aCurrentPlaylist[aCurrentPlaylist.Length - 1].endTime * i;
                m_lPlaylist.AddLast(pbi);
            }
        }

        // Reset Management Values. Add on an additional half second to the End Song Time. This gives a slight cooldown time after the song finishes before the Sheet music returns to screen.
        m_fPlaytime    = 0.0f;
        m_fEndSongTime = m_lPlaylist.Last.Value.endTime + 0.5f;
    }
Example #2
0
        /// <summary>
        /// Reports the playback start.
        /// </summary>
        /// <param name="message">The message.</param>
        private void ReportPlaybackStart(WebSocketMessageInfo message)
        {
            _logger.Debug("Received PlaybackStart message");

            var session = GetSessionFromMessage(message);

            if (session != null && session.User != null)
            {
                var vals = message.Data.Split('|');

                var item = _dtoService.GetItemByDtoId(vals[0]);

                var queueableMediaTypes = string.Empty;
                var canSeek             = true;

                if (vals.Length > 1)
                {
                    canSeek = string.Equals(vals[1], "true", StringComparison.OrdinalIgnoreCase);
                }
                if (vals.Length > 2)
                {
                    queueableMediaTypes = vals[2];
                }

                var info = new PlaybackInfo
                {
                    CanSeek             = canSeek,
                    Item                = item,
                    SessionId           = session.Id,
                    QueueableMediaTypes = queueableMediaTypes.Split(',').ToList()
                };

                _sessionManager.OnPlaybackStart(info);
            }
        }
Example #3
0
        private void CreateMediaPlayer()
        {
            _MediaElement = new MediaElement
            {
                LoadedBehavior   = MediaState.Manual,
                UnloadedBehavior = MediaState.Manual,
                IsMuted          = true,
                IsHitTestVisible = false
            };

            _VisualTargetSource.RootVisual = _MediaElement;

            _MediaElement.MediaOpened += MediaPlayer_Opened;
            _MediaElement.MediaEnded  += MediaPlayer_Ended;
            _MediaElement.MediaFailed += MediaPlayer_Failed;

            if (_CanPlay && _NextToPlay != null)
            {
                _CanPlay = false;

                _MediaElement.Source = new Uri(_NextToPlay.FileName);
                _MediaElement.Width  = _NextToPlay.Width;
                _MediaElement.Height = _NextToPlay.Height;
                _MediaElement.Play();

                _NextToPlay = null;
            }
        }
        private void RemoveOldPlayinfo(List <PlaybackInfo> active_list)
        {
            List <string> key_list = new List <string>();

            foreach (string key in playback_trackers.Keys)
            {
                key_list.Add(key);
            }

            foreach (string key in key_list)
            {
                PlaybackInfo playback_info = playback_trackers[key];
                if (active_list.Contains(playback_info) == false)
                {
                    _logger.Info("Saving final duration for Item : " + key);
                    TimeSpan diff = DateTime.Now.Subtract(playback_info.Date);
                    playback_info.PlaybackDuration = (int)diff.TotalSeconds;

                    // if we had a last paused increment paused time
                    if (playback_info.LastPauseTime != null)
                    {
                        TimeSpan pause_diff = DateTime.Now.Subtract((DateTime)playback_info.LastPauseTime);
                        playback_info.LastPauseTime   = null;
                        playback_info.PausedDuration += (int)pause_diff.TotalSeconds;
                    }

                    _repository.UpdatePlaybackAction(playback_info);

                    _logger.Info("Removing Old Key from playback_trackers : " + key);
                    playback_trackers.Remove(key);
                }
            }
        }
Example #5
0
        public void Play(string fileName, double width, double height)
        {
            Dispatcher dispatcher;

            lock (_Thread)
            {
                _NextToPlay = new PlaybackInfo
                {
                    FileName = fileName,
                    Width    = width,
                    Height   = height
                };

                dispatcher = Dispatcher.FromThread(_Thread);

                if (dispatcher == null)
                {
                    return;
                }
            }

            dispatcher.InvokeAsync(() =>
            {
                lock (_Thread)
                {
                    if (_CanPlay)
                    {
                        DestroyMediaPlayer();
                        CreateMediaPlayer();
                    }
                }
            });
        }
Example #6
0
    public PlaybackInfo CreatePlayback()
    {
        PlaybackInfo result = new PlaybackInfo();

        m_playerbackInfo.Add(result);
        return(result);
    }
Example #7
0
        void airplayServer_PlaybackInfoRequested(object sender, PlaybackInfoEventArgs e)
        {
            AirplayVideoPlayer currentVideoPlayer = getPlayer <AirplayVideoPlayer>();

            if (currentVideoPlayer != null)
            {
                PlaybackInfo playbackInfo = e.PlaybackInfo;
                playbackInfo.Duration = currentVideoPlayer.Duration.TotalSeconds;
                playbackInfo.Position = currentVideoPlayer.CurrentTime.TotalSeconds;
                playbackInfo.PlaybackLikelyToKeepUp = true;
                playbackInfo.ReadyToPlay            = true;
                PlaybackTimeRange timeRange = new PlaybackTimeRange();
                timeRange.Duration = playbackInfo.Duration;
                playbackInfo.LoadedTimeRanges.Add(timeRange);
                playbackInfo.SeekableTimeRanges.Add(timeRange);
                if (currentVideoPlayer.IsPaused)
                {
                    playbackInfo.Rate = 0;
                }
                else
                {
                    playbackInfo.Rate = 1;
                }
            }
        }
Example #8
0
 private void SetPlaybackInfo(PlaybackInfo info)
 {
     playbackInfo.Artist = info.Artist;
     playbackInfo.Image  = info.Image;
     playbackInfo.Status = info.Status;
     playbackInfo.Title  = info.Title;
     hasChanges          = true;
 }
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    //	* New Methods: Play Current Note
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    public void PlayNote(TambourineSoundsManager.SoundTypes eDesiredSound, float visibilityTime)
    {
        PlaybackInfo pbi = new PlaybackInfo();

        pbi.type      = eDesiredSound;
        pbi.startTime = 0.0f;
        pbi.endTime   = visibilityTime;
        StartCoroutine(PlayNote(pbi));
    }
 private void SavePlayStarted(PlaybackInfo playback_info)
 {
     if (playback_info.StartupSaved == false)
     {
         _logger.Info("Saving PlaybackInfo to DB");
         _repository.AddPlaybackAction(playback_info);
         playback_info.StartupSaved = true;
     }
 }
Example #11
0
        private void ChangePlayback(bool canChange, PlaybackInfo mode)
        {
            if (!canChange || InvalidState)
            {
                return;
            }
            var pb = new Playback(Zone.SelectedInput, mode);

            pb.Send(TheController, RefreshOnSuccess);
        }
    private IEnumerator PlayNote(PlaybackInfo playbackInfo, float WaitTime)
    {
        yield return(new WaitForSeconds(WaitTime));

        m_rTambourineSoundsManager.PlayTambourineSound(playbackInfo.type);
        m_rTambourineSoundsManager.HighlightSoundObject(playbackInfo.type);

        // See other Overloaded Method
        float waitTime = playbackInfo.endTime - playbackInfo.startTime;

        yield return(new WaitForSeconds(waitTime * 0.65f));

        m_rTambourineSoundsManager.RevertSoundObject(playbackInfo.type);
    }
    private IEnumerator PlayNote(PlaybackInfo playbackInfo)
    {
        m_rTambourineSoundsManager.PlayTambourineSound(playbackInfo.type);
        m_rTambourineSoundsManager.HighlightSoundObject(playbackInfo.type);

        // Wait For 65% of the waiting period, then revert the visual cue back to the normal sprite. Then wait the for remaining 35%.
        // This is so that the visual cues do not stack upon each other and make the sounds/visual cues appear so suddenly. Additionally this also
        // helps prevent two consecutive visual cues from looking like one long visual cue.
        float waitTime = playbackInfo.endTime - playbackInfo.startTime;

        yield return(new WaitForSeconds(waitTime * 0.65f));

        m_rTambourineSoundsManager.RevertSoundObject(playbackInfo.type);
    }
Example #14
0
        public PlaybackInfoPipeClient()
        {
            pipeThread   = new Thread(new ThreadStart(run));
            playbackInfo = new PlaybackInfo();
            string dir = getSubDirectory();

            playbackServerProcess = new Process();
            playbackServerProcess.StartInfo.FileName         = dir + "\\PlaybackInfoService.exe";
            playbackServerProcess.StartInfo.CreateNoWindow   = true;
            playbackServerProcess.StartInfo.ErrorDialog      = false;
            playbackServerProcess.StartInfo.WorkingDirectory = dir;
            playbackServerProcess.StartInfo.WindowStyle      = ProcessWindowStyle.Hidden;
            //playbackServerProcess.StartInfo.UseShellExecute = false;
            client = new NamedPipeClientStream("PipesOfPiece");
        }
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    //	* New Method: Resize Array
    //	: Simply Resizes an array and repopulates its memory
    //	  with its previous data.
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#if UNITY_EDITOR
    public void ResizePlaylistArray(Playlist ePlaylist, int NewSize)
    {
        PlaybackInfo[] NewPlaybackInfo = new PlaybackInfo[NewSize];
        PlaybackInfo[] OldInfo         = GetPlaylist(ePlaylist);

        for (int i = 0; i < NewPlaybackInfo.Length; ++i)
        {
            NewPlaybackInfo[i] = new PlaybackInfo();
            if (i < OldInfo.Length)
            {
                NewPlaybackInfo[i].type = OldInfo[i].type;
            }
        }

        m_arTrackSoundInfo[(int)ePlaylist].notes = NewPlaybackInfo;
    }
Example #16
0
 public void GetPlaybackInfo(PlaybackInfo playbackInfo)
 {
     if (hasStarted && m_Playback.Duration > 0)
     {
         playbackInfo.Duration = m_Playback.Duration / (float)COMHelper.UNITS;
         playbackInfo.Position = m_Playback.Position / (float)COMHelper.UNITS;
         playbackInfo.PlaybackLikelyToKeepUp = true;
         playbackInfo.ReadyToPlay            = true;
         PlaybackTimeRange timeRange = new PlaybackTimeRange()
         {
             Duration = playbackInfo.Duration
         };
         playbackInfo.LoadedTimeRanges.Add(timeRange);
         playbackInfo.SeekableTimeRanges.Add(timeRange);
         playbackInfo.Rate = m_Playback.IsPaused || hasFinished ? 0 : 1;
     }
 }
Example #17
0
        /// <summary>
        /// Posts the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        public void Post(OnPlaybackStart request)
        {
            var user = _userManager.GetUserById(request.UserId);

            var item = _dtoService.GetItemByDtoId(request.Id, user.Id);

            var queueableMediaTypes = (request.QueueableMediaTypes ?? string.Empty);

            var info = new PlaybackInfo
            {
                CanSeek             = request.CanSeek,
                Item                = item,
                SessionId           = GetSession().Id,
                QueueableMediaTypes = queueableMediaTypes.Split(',').ToList()
            };

            _sessionManager.OnPlaybackStart(info);
        }
Example #18
0
        /// <summary>
        /// Used to report that playback has started for an item
        /// </summary>
        /// <param name="info">The info.</param>
        /// <returns>Task.</returns>
        /// <exception cref="System.ArgumentNullException">info</exception>
        public async Task OnPlaybackStart(PlaybackInfo info)
        {
            if (info == null)
            {
                throw new ArgumentNullException("info");
            }
            if (info.SessionId == Guid.Empty)
            {
                throw new ArgumentNullException("info");
            }

            var session = Sessions.First(i => i.Id.Equals(info.SessionId));

            var item = info.Item;

            UpdateNowPlayingItem(session, item, false, false);

            session.CanSeek             = info.CanSeek;
            session.QueueableMediaTypes = info.QueueableMediaTypes;

            var key = item.GetUserDataKey();

            var user = session.User;

            var data = _userDataRepository.GetUserData(user.Id, key);

            data.PlayCount++;
            data.LastPlayedDate = DateTime.UtcNow;

            if (!(item is Video))
            {
                data.Played = true;
            }

            await _userDataRepository.SaveUserData(user.Id, info.Item, data, UserDataSaveReason.PlaybackStart, CancellationToken.None).ConfigureAwait(false);

            // Nothing to save here
            // Fire events to inform plugins
            EventHelper.QueueEventIfNotNull(PlaybackStart, this, new PlaybackProgressEventArgs
            {
                Item = item,
                User = user
            }, _logger);
        }
Example #19
0
        private void run()
        {
            StreamReader reader = null;

            try {
                while (!client.IsConnected)
                {
                    try {
                        client.Connect(100);
                    }
                    catch (Exception e) { }
                }
                reader = new StreamReader(client);
                while (true)
                {
                    string line = reader.ReadLine();
                    if (line != null && line.Length > 0)
                    {
                        PlaybackInfo info = ConvertJson(line);
                        if (info.IsStatusOnly)
                        {
                            SetPlaybackStatus(info.Status);
                        }
                        else
                        {
                            SetPlaybackInfo(info);
                        }
                    }
                }
            }
            catch (ThreadAbortException) {
                if (IsProcessRunning(playbackServerProcess))
                {
                    playbackServerProcess.Kill();
                }
                if (reader != null)
                {
                    reader.Close();
                }
                client.Close();
            }
        }
Example #20
0
 public void SetPlayerIndex(int index)
 {
     m_spawnTime       = Time.fixedTime;
     m_playerIndex     = index;
     m_playbackStorage = GameObject.FindGameObjectWithTag("PlaybackStorage");
     if (m_playbackStorage != null)
     {
         s_playbackStorage PlaybackStorageScript = m_playbackStorage.GetComponent <s_playbackStorage>();
         if (!PlaybackStorageScript.HasPlaybackData(m_playerIndex))
         {
             m_bIsRecording = true;
             m_playbackInfo = PlaybackStorageScript.CreatePlayback();
         }
         else
         {
             GetComponent <SpriteRenderer>().material = GhostMaterial;
             m_playbackInfo = PlaybackStorageScript.GetPlayback(m_playerIndex);
         }
     }
 }
        private PlaybackInfo GetPlaybackInfo(SessionInfo session)
        {
            string userId             = session.UserId;
            string deviceId           = session.DeviceId;
            string deviceName         = session.DeviceName;
            string clientName         = session.Client;
            string session_playing_id = session.NowPlayingItem.Id;

            string key = deviceId + "-" + userId + "-" + session_playing_id;

            PlaybackInfo playback_info = null;

            if (playback_trackers.ContainsKey(key))
            {
                //_logger.Info("Existing tracker found! : " + key);
                playback_info = playback_trackers[key];
            }
            else
            {
                _logger.Info("Adding PlaybackInfo to playback_trackers : " + key);
                playback_info = new PlaybackInfo();

                BaseItemDto item = session.NowPlayingItem;

                playback_info.Key            = key;
                playback_info.Date           = DateTime.Now;
                playback_info.UserId         = userId;
                playback_info.DeviceName     = deviceName;
                playback_info.ClientName     = clientName;
                playback_info.ItemId         = session_playing_id;
                playback_info.ItemName       = GetItemName(session.NowPlayingItem);
                playback_info.PlaybackMethod = GetPlaybackMethod(session);
                playback_info.ItemType       = session.NowPlayingItem.Type;
                playback_info.ItemType       = session.NowPlayingItem.Type;

                playback_trackers.Add(key, playback_info);
            }

            return(playback_info);
        }
        private List <PlaybackInfo> ProcessSessions()
        {
            List <PlaybackInfo> active_playinfo_list = new List <PlaybackInfo>();

            foreach (SessionInfo session in _sessionManager.Sessions)
            {
                if (session.NowPlayingItem == null)
                {
                    // nothing playing so move on to next
                    continue;
                }

                PlaybackInfo playback_info = GetPlaybackInfo(session);
                active_playinfo_list.Add(playback_info);
                SavePlayStarted(playback_info);

                // if we had a last paused increment paused time
                if (playback_info.LastPauseTime != null)
                {
                    TimeSpan pause_diff = DateTime.Now.Subtract((DateTime)playback_info.LastPauseTime);
                    playback_info.LastPauseTime   = null;
                    playback_info.PausedDuration += (int)pause_diff.TotalSeconds;
                }
                // if paused then set this interval paused start time
                if (session.PlayState != null && session.PlayState.IsPaused)
                {
                    playback_info.LastPauseTime = DateTime.Now;
                }

                TimeSpan diff = DateTime.Now.Subtract(playback_info.Date);
                playback_info.PlaybackDuration = (int)diff.TotalSeconds;

                _repository.UpdatePlaybackAction(playback_info);
            }

            return(active_playinfo_list);
        }
Example #23
0
        void airplayServer_PlaybackInfoRequested(object sender, PlaybackInfoEventArgs e)
        {
            invoke(delegate()
            {
                if (isVideoPlaying)
                {
                    PlaybackInfo playbackInfo           = e.PlaybackInfo;
                    playbackInfo.Duration               = currentVideoPlayer.Duration;
                    playbackInfo.Position               = currentVideoPlayer.CurrentPosition;
                    playbackInfo.PlaybackLikelyToKeepUp = true;
                    playbackInfo.ReadyToPlay            = true;

                    AvailableTimerange availableTimerange = currentVideoPlayer.GetAvailableTimerange();
                    PlaybackTimeRange timeRange           = new PlaybackTimeRange();
                    if (availableTimerange != null)
                    {
                        timeRange.Start    = availableTimerange.StartTime;
                        timeRange.Duration = availableTimerange.EndTime - availableTimerange.StartTime;
                    }
                    else
                    {
                        timeRange.Duration = currentVideoPlayer.Duration;
                    }
                    playbackInfo.LoadedTimeRanges.Add(timeRange);
                    playbackInfo.SeekableTimeRanges.Add(timeRange);

                    if (currentVideoPlayer.Paused)
                    {
                        playbackInfo.Rate = 0;
                    }
                    else
                    {
                        playbackInfo.Rate = 1;
                    }
                }
            });
        }
Example #24
0
        /// <summary>
        /// Used to report that playback has started for an item
        /// </summary>
        /// <param name="info">The info.</param>
        /// <returns>Task.</returns>
        /// <exception cref="System.ArgumentNullException">info</exception>
        public async Task OnPlaybackStart(PlaybackInfo info)
        {
            if (info == null)
            {
                throw new ArgumentNullException("info");
            }
            if (info.SessionId == Guid.Empty)
            {
                throw new ArgumentNullException("info");
            }

            var session = Sessions.First(i => i.Id.Equals(info.SessionId));

            var item = info.Item;

            UpdateNowPlayingItem(session, item, false, false);

            session.CanSeek             = info.CanSeek;
            session.QueueableMediaTypes = info.QueueableMediaTypes;

            var key = item.GetUserDataKey();

            var users = GetUsers(session);

            foreach (var user in users)
            {
                await OnPlaybackStart(user.Id, key, item).ConfigureAwait(false);
            }

            // Nothing to save here
            // Fire events to inform plugins
            EventHelper.QueueEventIfNotNull(PlaybackStart, this, new PlaybackProgressEventArgs
            {
                Item  = item,
                Users = users
            }, _logger);
        }
Example #25
0
 public Playback(Input i, PlaybackInfo mode)
 {
     Input = i;
     Mode  = mode;
 }
Example #26
0
        public async Task StartPlaybackTimer(PlaybackProgressEventArgs e)
        {
            _logger.LogInformation("StartPlaybackTimer : Entered");
            await Task.Delay(20000);

            try
            {
                var session = _sessionManager.GetSession(e.DeviceId, e.ClientName, "");
                if (session != null)
                {
                    string event_playing_id = e.Item.Id.ToString("N");

                    string event_user_id     = e.Users[0].Id.ToString("N");
                    long   event_user_id_int = e.Users[0].InternalId;

                    string session_playing_id = "";
                    if (session.NowPlayingItem != null)
                    {
                        session_playing_id = session.NowPlayingItem.Id.ToString("N");
                    }
                    string session_user_id = "";

                    _logger.LogInformation("session.RemoteEndPoint : {RemoteEndPoint}", session.RemoteEndPoint);

                    if (session.UserId != Guid.Empty)
                    {
                        session_user_id = session.UserId.ToString("N");
                    }

                    string play_method = "na";
                    if (session.PlayState != null && session.PlayState.PlayMethod != null)
                    {
                        play_method = session.PlayState.PlayMethod.Value.ToString();
                    }
                    if (session.PlayState != null && session.PlayState.PlayMethod == MediaBrowser.Model.Session.PlayMethod.Transcode)
                    {
                        if (session.TranscodingInfo != null)
                        {
                            string video_codec = "direct";
                            if (session.TranscodingInfo.IsVideoDirect == false)
                            {
                                video_codec = session.TranscodingInfo.VideoCodec;
                            }
                            string audio_codec = "direct";
                            if (session.TranscodingInfo.IsAudioDirect == false)
                            {
                                audio_codec = session.TranscodingInfo.AudioCodec;
                            }
                            play_method += " (v:" + video_codec + " a:" + audio_codec + ")";
                        }
                    }

                    string item_name = GetItemName(e.Item);
                    string item_id   = e.Item.Id.ToString("N");
                    string item_type = e.MediaInfo.Type;

                    _logger.LogInformation("StartPlaybackTimer : event_playing_id     = {EventPlayingId}", event_playing_id);
                    _logger.LogInformation("StartPlaybackTimer : event_user_id        = {EventUserId}", event_user_id);
                    _logger.LogInformation("StartPlaybackTimer : event_user_id_int    = {EventUserIdInternal}", event_user_id_int);
                    _logger.LogInformation("StartPlaybackTimer : session_playing_id   = {SessionPlayingId}", session_playing_id);
                    _logger.LogInformation("StartPlaybackTimer : session_user_id      = {SessionUserId}", session_user_id);
                    _logger.LogInformation("StartPlaybackTimer : play_method          = {PlayMethod}", play_method);
                    _logger.LogInformation("StartPlaybackTimer : e.ClientName         = {ClientName}", e.ClientName);
                    _logger.LogInformation("StartPlaybackTimer : e.DeviceName         = {DeviceName}", e.DeviceName);
                    _logger.LogInformation("StartPlaybackTimer : ItemName             = {ItemName}", item_name);
                    _logger.LogInformation("StartPlaybackTimer : ItemId               = {ItemId}", item_id);
                    _logger.LogInformation("StartPlaybackTimer : ItemType             = {ItemType}", item_type);

                    PlaybackInfo play_info = new PlaybackInfo
                    {
                        Id             = Guid.NewGuid().ToString("N"),
                        Date           = DateTime.Now,
                        ClientName     = e.ClientName,
                        DeviceName     = e.DeviceName,
                        PlaybackMethod = play_method,
                        UserId         = event_user_id,
                        ItemId         = item_id,
                        ItemName       = item_name,
                        ItemType       = item_type
                    };

                    if (event_playing_id == session_playing_id && event_user_id == session_user_id)
                    {
                        _logger.LogInformation("StartPlaybackTimer : All matches, playback registered");

                        // update tracker with playback info
                        string key = e.DeviceId + "-" + e.Users[0].Id.ToString("N") + "-" + e.Item.Id.ToString("N");
                        if (playback_trackers.ContainsKey(key))
                        {
                            _logger.LogInformation("Playback tracker found, adding playback info : {Key}", key);
                            PlaybackTracker tracker = playback_trackers[key];
                            tracker.TrackedPlaybackInfo = play_info;

                            _logger.LogInformation("Saving playback tracking activity in DB");
                            _repository.AddPlaybackAction(tracker.TrackedPlaybackInfo);
                        }
                        else
                        {
                            _logger.LogInformation("Playback trackler not found : {Key}", key);
                        }
                    }
                    else
                    {
                        _logger.LogInformation("StartPlaybackTimer : Details do not match for play item");
                    }
                }
                else
                {
                    _logger.LogInformation("StartPlaybackTimer : session Not Found");
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "StartPlaybackTimer : Unexpected error occurred");
            }
            _logger.LogInformation("StartPlaybackTimer : Exited");
        }
 public VideoPlayer(PlaybackInfo info)
 {
     this.info = info;
 }
        public async System.Threading.Tasks.Task StartPlaybackTimer(PlaybackProgressEventArgs e)
        {
            _logger.Info("StartPlaybackTimer : Entered");
            await System.Threading.Tasks.Task.Delay(20000);

            try
            {
                var session = _sessionManager.GetSession(e.DeviceId, e.ClientName, "");
                if (session != null)
                {
                    string event_playing_id = e.Item.Id.ToString("N");
                    string event_user_id    = e.Users[0].Id.ToString("N");

                    string session_playing_id = "";
                    if (session.NowPlayingItem != null)
                    {
                        session_playing_id = session.NowPlayingItem.Id.ToString("N");
                    }
                    string session_user_id = "";

                    _logger.Info("session.RemoteEndPoint : " + session.RemoteEndPoint);

                    if (session.UserId != null)
                    {
                        session_user_id = ((Guid)session.UserId).ToString("N");
                    }

                    string play_method = "na";
                    if (session.PlayState != null && session.PlayState.PlayMethod != null)
                    {
                        play_method = session.PlayState.PlayMethod.Value.ToString();
                    }
                    if (session.PlayState != null && session.PlayState.PlayMethod == MediaBrowser.Model.Session.PlayMethod.Transcode)
                    {
                        if (session.TranscodingInfo != null)
                        {
                            string video_codec = "direct";
                            if (session.TranscodingInfo.IsVideoDirect == false)
                            {
                                video_codec = session.TranscodingInfo.VideoCodec;
                            }
                            string audio_codec = "direct";
                            if (session.TranscodingInfo.IsAudioDirect == false)
                            {
                                audio_codec = session.TranscodingInfo.AudioCodec;
                            }
                            play_method += " (v:" + video_codec + " a:" + audio_codec + ")";
                        }
                    }

                    string item_name = GetItemName(e.Item);
                    string item_id   = e.Item.Id.ToString("N");
                    string item_type = e.MediaInfo.Type;

                    _logger.Info("StartPlaybackTimer : event_playing_id   = " + event_playing_id);
                    _logger.Info("StartPlaybackTimer : event_user_id      = " + event_user_id);
                    _logger.Info("StartPlaybackTimer : session_playing_id = " + session_playing_id);
                    _logger.Info("StartPlaybackTimer : session_user_id    = " + session_user_id);
                    _logger.Info("StartPlaybackTimer : play_method        = " + play_method);
                    _logger.Info("StartPlaybackTimer : e.ClientName       = " + e.ClientName);
                    _logger.Info("StartPlaybackTimer : e.DeviceName       = " + e.DeviceName);
                    _logger.Info("StartPlaybackTimer : ItemName           = " + item_name);
                    _logger.Info("StartPlaybackTimer : ItemId             = " + item_id);
                    _logger.Info("StartPlaybackTimer : ItemType           = " + item_type);

                    PlaybackInfo play_info = new PlaybackInfo();
                    play_info.Id             = Guid.NewGuid().ToString("N");
                    play_info.Date           = DateTime.Now;
                    play_info.ClientName     = e.ClientName;
                    play_info.DeviceName     = e.DeviceName;
                    play_info.PlaybackMethod = play_method;
                    play_info.UserId         = event_user_id;
                    play_info.ItemId         = item_id;
                    play_info.ItemName       = item_name;
                    play_info.ItemType       = item_type;

                    if (event_playing_id == session_playing_id && event_user_id == session_user_id)
                    {
                        _logger.Info("StartPlaybackTimer : All matches, playback registered");

                        // update tracker with playback info
                        string key = e.DeviceId + "-" + e.Users[0].Id.ToString("N") + "-" + e.Item.Id.ToString("N");
                        if (playback_trackers.ContainsKey(key))
                        {
                            _logger.Info("Playback tracker found, adding playback info : " + key);
                            PlaybackTracker tracker = playback_trackers[key];
                            tracker.TrackedPlaybackInfo = play_info;

                            _logger.Info("Saving playback tracking activity in DB");
                            _repository.AddPlaybackAction(tracker.TrackedPlaybackInfo);
                        }
                        else
                        {
                            _logger.Info("Playback trackler not found : " + key);
                        }
                    }
                    else
                    {
                        _logger.Info("StartPlaybackTimer : Details do not match for play item");
                    }
                }
                else
                {
                    _logger.Info("StartPlaybackTimer : session Not Found");
                }
            }
            catch (Exception exception)
            {
                _logger.Info("StartPlaybackTimer : Error = " + exception.Message + "\n" + exception.StackTrace);
            }
            _logger.Info("StartPlaybackTimer : Exited");
        }