Example #1
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));
        }
Example #2
0
        private async Task SeekAfterTransportChange(long positionTicks)
        {
            const int maxWait     = 15000000;
            const int interval    = 500;
            var       currentWait = 0;

            while (_device.TransportState != TRANSPORTSTATE.PLAYING && currentWait < maxWait)
            {
                await Task.Delay(interval).ConfigureAwait(false);

                currentWait += interval;
            }

            await _device.Seek(TimeSpan.FromTicks(positionTicks)).ConfigureAwait(false);
        }
Example #3
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 && !info.IsDirectStream)
                {
                    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);

                    if (newItem.StreamInfo.IsDirectStream)
                    {
                        await _device.Seek(TimeSpan.FromTicks(newPosition)).ConfigureAwait(false);
                    }
                    return;
                }
                await _device.Seek(TimeSpan.FromTicks(newPosition)).ConfigureAwait(false);
            }
        }