Esempio n. 1
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, key, data, CancellationToken.None).ConfigureAwait(false);

            // Nothing to save here
            // Fire events to inform plugins
            EventHelper.QueueEventIfNotNull(PlaybackStart, this, new PlaybackProgressEventArgs
            {
                Item = item,
                User = user
            }, _logger);
        }
        /// <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.UserId.HasValue)
            {
                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()
                };

                if (vals.Length > 3)
                {
                    info.MediaSourceId = vals[3];
                }

                if (vals.Length > 4 && !string.IsNullOrWhiteSpace(vals[4]))
                {
                    info.AudioStreamIndex = int.Parse(vals[4], _usCulture);
                }

                if (vals.Length > 5 && !string.IsNullOrWhiteSpace(vals[5]))
                {
                    info.SubtitleStreamIndex = int.Parse(vals[5], _usCulture);
                }

                _sessionManager.OnPlaybackStart(info);
            }
        }
Esempio n. 3
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);
        }
        /// <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);
            }
        }