fixes #850 - Support dlna Play To playlist

pull/702/head
Luke Pulverenti 11 years ago
parent d0b6fd938d
commit 5c9210672e

@ -293,7 +293,13 @@ namespace MediaBrowser.Dlna.PlayTo
.ConfigureAwait(false); .ConfigureAwait(false);
await Task.Delay(50).ConfigureAwait(false); await Task.Delay(50).ConfigureAwait(false);
// If it's already in a playing state, this will throw an error
// TODO: What if state is transitioning?
if (TransportState != TRANSPORTSTATE.PLAYING)
{
await SetPlay().ConfigureAwait(false); await SetPlay().ConfigureAwait(false);
}
RestartTimer(); RestartTimer();
} }

@ -100,7 +100,7 @@ namespace MediaBrowser.Dlna.PlayTo
return _serverAddress; return _serverAddress;
} }
async void _SsdpHandler_MessageReceived(object sender, SsdpMessageEventArgs e) void _SsdpHandler_MessageReceived(object sender, SsdpMessageEventArgs e)
{ {
string nts; string nts;
e.Headers.TryGetValue("NTS", out nts); e.Headers.TryGetValue("NTS", out nts);
@ -148,7 +148,17 @@ namespace MediaBrowser.Dlna.PlayTo
_logger.ErrorException("Error reporting progress", ex); _logger.ErrorException("Error reporting progress", ex);
} }
//await SetNext().ConfigureAwait(false); var playedToCompletion = _device.Position.Ticks == 0 ||
(_device.Duration.HasValue && _device.Position.Ticks >= _device.Duration.Value.Ticks);
if (playedToCompletion)
{
await SetPlaylistIndex(_currentPlaylistIndex + 1).ConfigureAwait(false);
}
else
{
Playlist.Clear();
}
} }
async void _device_PlaybackStart(object sender, PlaybackStartEventArgs e) async void _device_PlaybackStart(object sender, PlaybackStartEventArgs e)
@ -252,8 +262,6 @@ namespace MediaBrowser.Dlna.PlayTo
Playlist.AddRange(playlist); Playlist.AddRange(playlist);
} }
_logger.Debug("{0} - Playing {1} items", _session.DeviceName, playlist.Count);
if (!String.IsNullOrWhiteSpace(command.ControllingUserId)) if (!String.IsNullOrWhiteSpace(command.ControllingUserId))
{ {
await _sessionManager.LogSessionActivity(_session.Client, _session.ApplicationVersion, _session.DeviceId, await _sessionManager.LogSessionActivity(_session.Client, _session.ApplicationVersion, _session.DeviceId,
@ -283,10 +291,10 @@ namespace MediaBrowser.Dlna.PlayTo
} }
case PlaystateCommand.NextTrack: case PlaystateCommand.NextTrack:
return SetNext(); return SetPlaylistIndex(_currentPlaylistIndex + 1);
case PlaystateCommand.PreviousTrack: case PlaystateCommand.PreviousTrack:
return SetPrevious(); return SetPlaylistIndex(_currentPlaylistIndex - 1);
} }
return Task.FromResult(true); return Task.FromResult(true);
@ -361,6 +369,7 @@ namespace MediaBrowser.Dlna.PlayTo
#region Playlist #region Playlist
private int _currentPlaylistIndex;
private readonly List<PlaylistItem> _playlist = new List<PlaylistItem>(); private readonly List<PlaylistItem> _playlist = new List<PlaylistItem>();
private List<PlaylistItem> Playlist private List<PlaylistItem> Playlist
{ {
@ -524,63 +533,33 @@ namespace MediaBrowser.Dlna.PlayTo
{ {
Playlist.Clear(); Playlist.Clear();
Playlist.AddRange(items); Playlist.AddRange(items);
await SetNext(); _logger.Debug("{0} - Playing {1} items", _session.DeviceName, Playlist.Count);
return true;
}
private async Task SetNext() await SetPlaylistIndex(0).ConfigureAwait(false);
{ return true;
if (!Playlist.Any() || Playlist.All(i => i.PlayState != 0))
{
return;
} }
var currentitem = Playlist.FirstOrDefault(i => i.PlayState == 1); private async Task SetPlaylistIndex(int index)
if (currentitem != null)
{ {
currentitem.PlayState = 2; if (index < 0 || index >= Playlist.Count)
}
var nextTrack = Playlist.FirstOrDefault(i => i.PlayState == 0);
if (nextTrack == null)
{ {
Playlist.Clear();
await _device.SetStop(); await _device.SetStop();
return; return;
} }
nextTrack.PlayState = 1; _currentPlaylistIndex = index;
var currentitem = Playlist[index];
var dlnaheaders = GetDlnaHeaders(nextTrack); var dlnaheaders = GetDlnaHeaders(currentitem);
await _device.SetAvTransport(nextTrack.StreamUrl, dlnaheaders, nextTrack.Didl); await _device.SetAvTransport(currentitem.StreamUrl, dlnaheaders, currentitem.Didl);
var streamInfo = nextTrack.StreamInfo; var streamInfo = currentitem.StreamInfo;
if (streamInfo.StartPositionTicks > 0 && streamInfo.IsDirectStream) if (streamInfo.StartPositionTicks > 0 && streamInfo.IsDirectStream)
await _device.Seek(TimeSpan.FromTicks(streamInfo.StartPositionTicks)); await _device.Seek(TimeSpan.FromTicks(streamInfo.StartPositionTicks));
} }
public Task SetPrevious()
{
if (!Playlist.Any() || Playlist.All(i => i.PlayState != 2))
return Task.FromResult(false);
var currentitem = Playlist.FirstOrDefault(i => i.PlayState == 1);
var prevTrack = Playlist.LastOrDefault(i => i.PlayState == 2);
if (currentitem != null)
{
currentitem.PlayState = 0;
}
if (prevTrack == null)
return Task.FromResult(false);
prevTrack.PlayState = 1;
return _device.SetAvTransport(prevTrack.StreamInfo.ToDlnaUrl(GetServerAddress()), GetDlnaHeaders(prevTrack), prevTrack.Didl);
}
#endregion #endregion
private bool _disposed; private bool _disposed;

Loading…
Cancel
Save