enable play to

pull/702/head
Luke Pulverenti 11 years ago
parent f2261a669e
commit 44e32d841b

@ -1,11 +1,11 @@
using MediaBrowser.Common.Net; using MediaBrowser.Common.Net;
using MediaBrowser.Model.Logging;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Timers;
using System.Xml.Linq; using System.Xml.Linq;
using MediaBrowser.Model.Logging;
namespace MediaBrowser.Dlna.PlayTo namespace MediaBrowser.Dlna.PlayTo
{ {
@ -16,7 +16,7 @@ namespace MediaBrowser.Dlna.PlayTo
#region Fields & Properties #region Fields & Properties
private Timer _dt; private Timer _timer;
public DeviceProperties Properties { get; set; } public DeviceProperties Properties { get; set; }
@ -29,7 +29,7 @@ namespace MediaBrowser.Dlna.PlayTo
} }
} }
string _currentId = String.Empty; private string _currentId = String.Empty;
public string CurrentId public string CurrentId
{ {
get get
@ -101,9 +101,7 @@ namespace MediaBrowser.Dlna.PlayTo
{ {
get get
{ {
if (TransportState == "PAUSED" || TransportState == "PAUSED_PLAYBACK") return TransportState == "PAUSED" || TransportState == "PAUSED_PLAYBACK";
return true;
return false;
} }
} }
@ -115,16 +113,13 @@ namespace MediaBrowser.Dlna.PlayTo
} }
} }
public DateTime UpdateTime public DateTime UpdateTime { get; private set; }
{ get; private set; }
#endregion #endregion
private readonly IHttpClient _httpClient; private readonly IHttpClient _httpClient;
private readonly ILogger _logger; private readonly ILogger _logger;
#region Constructor & Initializer
public Device(DeviceProperties deviceProperties, IHttpClient httpClient, ILogger logger) public Device(DeviceProperties deviceProperties, IHttpClient httpClient, ILogger logger)
{ {
Properties = deviceProperties; Properties = deviceProperties;
@ -132,15 +127,31 @@ namespace MediaBrowser.Dlna.PlayTo
_logger = logger; _logger = logger;
} }
internal void Start() private int GetTimerIntervalMs()
{
return 10000;
}
public void Start()
{ {
UpdateTime = DateTime.UtcNow; UpdateTime = DateTime.UtcNow;
_dt = new Timer(1000);
_dt.Elapsed += dt_Elapsed; var interval = GetTimerIntervalMs();
_dt.Start();
_timer = new Timer(TimerCallback, null, interval, interval);
} }
#endregion private void RestartTimer()
{
var interval = GetTimerIntervalMs();
_timer.Change(interval, interval);
}
private void StopTimer()
{
_timer.Change(Timeout.Infinite, Timeout.Infinite);
}
#region Commanding #region Commanding
@ -172,10 +183,9 @@ namespace MediaBrowser.Dlna.PlayTo
return SetVolume(0); return SetVolume(0);
} }
int tmp = _muteVol; var tmp = _muteVol;
_muteVol = 0; _muteVol = 0;
return SetVolume(tmp); return SetVolume(tmp);
} }
public async Task<bool> SetVolume(int value) public async Task<bool> SetVolume(int value)
@ -218,7 +228,8 @@ namespace MediaBrowser.Dlna.PlayTo
public async Task<bool> SetAvTransport(string url, string header, string metaData) public async Task<bool> SetAvTransport(string url, string header, string metaData)
{ {
_dt.Stop(); StopTimer();
TransportState = "STOPPED"; TransportState = "STOPPED";
CurrentId = "0"; CurrentId = "0";
@ -251,7 +262,8 @@ namespace MediaBrowser.Dlna.PlayTo
} }
_count = 5; _count = 5;
_dt.Start(); RestartTimer();
return true; return true;
} }
@ -273,9 +285,11 @@ namespace MediaBrowser.Dlna.PlayTo
if (command == null) if (command == null)
return false; return false;
var dictionary = new Dictionary<string, string>(); var dictionary = new Dictionary<string, string>
dictionary.Add("NextURI", value); {
dictionary.Add("NextURIMetaData", CreateDidlMeta(metaData)); {"NextURI", value},
{"NextURIMetaData", CreateDidlMeta(metaData)}
};
var service = Properties.Services.FirstOrDefault(s => s.ServiceId == ServiceAvtransportId); var service = Properties.Services.FirstOrDefault(s => s.ServiceId == ServiceAvtransportId);
@ -351,19 +365,19 @@ namespace MediaBrowser.Dlna.PlayTo
// TODO: What is going on here // TODO: What is going on here
int _count = 5; int _count = 5;
async void dt_Elapsed(object sender, ElapsedEventArgs e) private async void TimerCallback(object sender)
{ {
if (_disposed) if (_disposed)
return; return;
((Timer)sender).Stop(); StopTimer();
try try
{ {
var hasTrack = await GetPositionInfo().ConfigureAwait(false); var hasTrack = await GetPositionInfo().ConfigureAwait(false);
// TODO: Why make these requests if hasTrack==false? // TODO: Why make these requests if hasTrack==false?
if (_count > 4) if (_count > 5)
{ {
await GetTransportInfo().ConfigureAwait(false); await GetTransportInfo().ConfigureAwait(false);
if (!hasTrack) if (!hasTrack)
@ -382,7 +396,8 @@ namespace MediaBrowser.Dlna.PlayTo
_count++; _count++;
if (_disposed) if (_disposed)
return; return;
((Timer)sender).Start();
RestartTimer();
} }
private async Task GetVolume() private async Task GetVolume()
@ -722,7 +737,7 @@ namespace MediaBrowser.Dlna.PlayTo
if (!_disposed) if (!_disposed)
{ {
_disposed = true; _disposed = true;
_dt.Stop(); _timer.Dispose();
} }
} }

@ -20,7 +20,7 @@ namespace MediaBrowser.Dlna.PlayTo
public void Run() public void Run()
{ {
//_manager.Start(); _manager.Start();
} }
#region Dispose #region Dispose

Loading…
Cancel
Save