Exemple #1
0
        private async Task Seek(long newPosition)
        {
            var media = _device.CurrentMediaInfo;

            if (media != null)
            {
                var info = StreamParams.ParseFromUrl(media.Url, _libraryManager, _mediaSourceManager);

                if (info.Item != null && !EnableClientSideSeek(info))
                {
                    var user    = _session.UserId.HasValue ? _userManager.GetUserById(_session.UserId.Value) : null;
                    var newItem = CreatePlaylistItem(info.Item, user, newPosition, info.MediaSourceId, info.AudioStreamIndex, info.SubtitleStreamIndex);

                    await _device.SetAvTransport(newItem.StreamUrl, GetDlnaHeaders(newItem), newItem.Didl).ConfigureAwait(false);

                    return;
                }
                await SeekAfterTransportChange(newPosition).ConfigureAwait(false);
            }
        }
Exemple #2
0
        private async Task <bool> SetNext()
        {
            if (!Playlist.Any() || Playlist.All(i => i.PlayState != 0))
            {
                return(true);
            }
            var currentitem = Playlist.FirstOrDefault(i => i.PlayState == 1);

            if (currentitem != null)
            {
                currentitem.PlayState = 2;
            }

            var nextTrack = Playlist.FirstOrDefault(i => i.PlayState == 0);

            if (nextTrack == null)
            {
                await _device.SetStop();

                return(true);
            }

            nextTrack.PlayState = 1;

            var dlnaheaders = GetDlnaHeaders(nextTrack);

            _logger.Debug("{0} - SetAvTransport Uri: {1} DlnaHeaders: {2}", _device.Properties.Name, nextTrack.StreamUrl, dlnaheaders);

            await _device.SetAvTransport(nextTrack.StreamUrl, dlnaheaders, nextTrack.Didl);

            var streamInfo = nextTrack.StreamInfo;

            if (streamInfo.StartPositionTicks > 0 && streamInfo.IsDirectStream)
            {
                await _device.Seek(TimeSpan.FromTicks(streamInfo.StartPositionTicks));
            }

            return(true);
        }
Exemple #3
0
        public Task SendPlaystateCommand(PlaystateRequest command, CancellationToken cancellationToken)
        {
            switch (command.Command)
            {
            case PlaystateCommand.Stop:
                Playlist.Clear();
                return(_device.SetStop());

            case PlaystateCommand.Pause:
                return(_device.SetPause());

            case PlaystateCommand.Unpause:
                return(_device.SetPlay());

            case PlaystateCommand.Seek:
                var playlistItem = Playlist.FirstOrDefault(p => p.PlayState == 1);
                if (playlistItem != null && playlistItem.Transcode && playlistItem.IsVideo && _currentItem != null)
                {
                    var newItem = CreatePlaylistItem(_currentItem, command.SeekPositionTicks ?? 0, GetServerAddress());
                    playlistItem.StartPositionTicks = newItem.StartPositionTicks;
                    playlistItem.StreamUrl          = newItem.StreamUrl;
                    playlistItem.Didl = newItem.Didl;
                    return(_device.SetAvTransport(playlistItem.StreamUrl, playlistItem.DlnaHeaders, playlistItem.Didl));
                }
                return(_device.Seek(TimeSpan.FromTicks(command.SeekPositionTicks ?? 0)));


            case PlaystateCommand.NextTrack:
                _currentItem = null;
                return(SetNext());

            case PlaystateCommand.PreviousTrack:
                _currentItem = null;
                return(SetPrevious());
            }

            return(Task.FromResult(true));
        }