diff --git a/MediaBrowser.Dlna/PlayTo/PlayToServerEntryPoint.cs b/MediaBrowser.Dlna/PlayTo/PlayToServerEntryPoint.cs
index b1afeb0f4..a6746cfc5 100644
--- a/MediaBrowser.Dlna/PlayTo/PlayToServerEntryPoint.cs
+++ b/MediaBrowser.Dlna/PlayTo/PlayToServerEntryPoint.cs
@@ -1,38 +1,105 @@
using MediaBrowser.Common.Net;
+using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Persistence;
using MediaBrowser.Controller.Plugins;
using MediaBrowser.Controller.Session;
using MediaBrowser.Model.Logging;
+using System;
namespace MediaBrowser.Dlna.PlayTo
{
public class PlayToServerEntryPoint : IServerEntryPoint
{
- private bool _disposed;
+ private PlayToManager _manager;
+ private readonly IServerConfigurationManager _config;
+ private readonly ILogger _logger;
+ private readonly ISessionManager _sessionManager;
+ private readonly IHttpClient _httpClient;
+ private readonly IItemRepository _itemRepo;
+ private readonly ILibraryManager _libraryManager;
+ private readonly INetworkManager _networkManager;
+ private readonly IUserManager _userManager;
- private readonly PlayToManager _manager;
-
- public PlayToServerEntryPoint(ILogManager logManager, ISessionManager sessionManager, IUserManager userManager, IHttpClient httpClient, INetworkManager networkManager, IItemRepository itemRepository, ILibraryManager libraryManager)
+ public PlayToServerEntryPoint(ILogManager logManager, IServerConfigurationManager config, ISessionManager sessionManager, IHttpClient httpClient, IItemRepository itemRepo, ILibraryManager libraryManager, INetworkManager networkManager, IUserManager userManager)
{
- _manager = new PlayToManager(logManager.GetLogger("PlayTo"), sessionManager, httpClient, itemRepository, libraryManager, networkManager, userManager);
+ _config = config;
+ _sessionManager = sessionManager;
+ _httpClient = httpClient;
+ _itemRepo = itemRepo;
+ _libraryManager = libraryManager;
+ _networkManager = networkManager;
+ _userManager = userManager;
+ _logger = logManager.GetLogger("PlayTo");
}
public void Run()
{
- //_manager.Start();
+ _config.ConfigurationUpdated += ConfigurationUpdated;
+ ReloadPlayToManager();
+ }
+
+ void ConfigurationUpdated(object sender, EventArgs e)
+ {
+ ReloadPlayToManager();
+ }
+
+ private void ReloadPlayToManager()
+ {
+ var isStarted = _manager != null;
+
+ if (_config.Configuration.DlnaOptions.EnablePlayTo && !isStarted)
+ {
+ StartPlayToManager();
+ }
+ else if (!_config.Configuration.DlnaOptions.EnablePlayTo && isStarted)
+ {
+ DisposePlayToManager();
+ }
+ }
+
+ private readonly object _syncLock = new object();
+ private void StartPlayToManager()
+ {
+ lock (_syncLock)
+ {
+ try
+ {
+ _manager = new PlayToManager(_logger, _sessionManager, _httpClient, _itemRepo, _libraryManager, _networkManager, _userManager);
+ _manager.Start();
+ }
+ catch (Exception ex)
+ {
+ _logger.ErrorException("Error starting PlayTo manager", ex);
+ }
+ }
+ }
+
+ private void DisposePlayToManager()
+ {
+ lock (_syncLock)
+ {
+ if (_manager != null)
+ {
+ try
+ {
+ _manager.Stop();
+ _manager.Dispose();
+ }
+ catch (Exception ex)
+ {
+ _logger.ErrorException("Error disposing PlayTo manager", ex);
+ }
+ _manager = null;
+ }
+ }
}
#region Dispose
public void Dispose()
{
- if (!_disposed)
- {
- _disposed = true;
- _manager.Stop();
- _manager.Dispose();
- }
+ DisposePlayToManager();
}
#endregion
diff --git a/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj b/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj
index 04296de35..8dd8a2a34 100644
--- a/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj
+++ b/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj
@@ -80,6 +80,9 @@
Configuration\BaseApplicationConfiguration.cs
+
+ Configuration\DlnaOptions.cs
+
Configuration\ManualLoginCategory.cs
diff --git a/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj b/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj
index 56f7fb99d..4cdcaae64 100644
--- a/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj
+++ b/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj
@@ -67,6 +67,9 @@
Configuration\BaseApplicationConfiguration.cs
+
+ Configuration\DlnaOptions.cs
+
Configuration\ManualLoginCategory.cs
diff --git a/MediaBrowser.Model/Configuration/DlnaOptions.cs b/MediaBrowser.Model/Configuration/DlnaOptions.cs
new file mode 100644
index 000000000..e6c24fdfb
--- /dev/null
+++ b/MediaBrowser.Model/Configuration/DlnaOptions.cs
@@ -0,0 +1,8 @@
+
+namespace MediaBrowser.Model.Configuration
+{
+ public class DlnaOptions
+ {
+ public bool EnablePlayTo { get; set; }
+ }
+}
diff --git a/MediaBrowser.Model/Configuration/ServerConfiguration.cs b/MediaBrowser.Model/Configuration/ServerConfiguration.cs
index 0bff8a1bd..c2765754e 100644
--- a/MediaBrowser.Model/Configuration/ServerConfiguration.cs
+++ b/MediaBrowser.Model/Configuration/ServerConfiguration.cs
@@ -212,6 +212,8 @@ namespace MediaBrowser.Model.Configuration
public string ServerName { get; set; }
public string WanDdns { get; set; }
+ public DlnaOptions DlnaOptions { get; set; }
+
///
/// Initializes a new instance of the class.
///
@@ -271,6 +273,8 @@ namespace MediaBrowser.Model.Configuration
};
MetadataOptions = options.ToArray();
+
+ DlnaOptions = new DlnaOptions();
}
}
diff --git a/MediaBrowser.Model/MediaBrowser.Model.csproj b/MediaBrowser.Model/MediaBrowser.Model.csproj
index 10aedb3ba..42ae7c396 100644
--- a/MediaBrowser.Model/MediaBrowser.Model.csproj
+++ b/MediaBrowser.Model/MediaBrowser.Model.csproj
@@ -60,6 +60,7 @@
+
diff --git a/MediaBrowser.Server.Implementations/Collections/CollectionManager.cs b/MediaBrowser.Server.Implementations/Collections/CollectionManager.cs
index 1cfcef514..9a196cc47 100644
--- a/MediaBrowser.Server.Implementations/Collections/CollectionManager.cs
+++ b/MediaBrowser.Server.Implementations/Collections/CollectionManager.cs
@@ -81,7 +81,13 @@ namespace MediaBrowser.Server.Implementations.Collections
throw new ArgumentNullException("parentId");
}
- return _libraryManager.GetItemById(parentId.Value) as Folder;
+ var folder = _libraryManager.GetItemById(parentId.Value) as Folder;
+
+ // Find an actual physical folder
+ if (folder is CollectionFolder)
+ {
+ return _libraryManager.RootFolder.Children.OfType().First(i => folder.PhysicalLocations.Contains(i.Path, StringComparer.OrdinalIgnoreCase));
+ }
}
return _libraryManager.RootFolder.Children.OfType().FirstOrDefault() ??
diff --git a/MediaBrowser.WebDashboard/Api/DashboardService.cs b/MediaBrowser.WebDashboard/Api/DashboardService.cs
index 19f213b2f..fa2ae278c 100644
--- a/MediaBrowser.WebDashboard/Api/DashboardService.cs
+++ b/MediaBrowser.WebDashboard/Api/DashboardService.cs
@@ -480,6 +480,7 @@ namespace MediaBrowser.WebDashboard.Api
"dashboardinfo.js",
"dashboardpage.js",
"directorybrowser.js",
+ "dlnasettings.js",
"editcollectionitems.js",
"edititemmetadata.js",
"edititempeople.js",
diff --git a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj
index 424192e28..4b2ce4833 100644
--- a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj
+++ b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj
@@ -213,6 +213,9 @@
PreserveNewest
+
+ PreserveNewest
+
PreserveNewest
@@ -483,6 +486,9 @@
PreserveNewest
+
+ PreserveNewest
+
PreserveNewest
diff --git a/MediaBrowser.sln b/MediaBrowser.sln
index 7ac158065..1d8a3bf26 100644
--- a/MediaBrowser.sln
+++ b/MediaBrowser.sln
@@ -254,4 +254,4 @@ Global
GlobalSection(Performance) = preSolution
HasPerformanceSessions = true
EndGlobalSection
-EndGlobal
+EndGlobal
\ No newline at end of file