From fbf3916bcec3ff6ba9e34d9756f0583ac90ea0ab Mon Sep 17 00:00:00 2001 From: LukePulverenti Luke Pulverenti luke pulverenti Date: Fri, 10 Aug 2012 09:18:30 -0400 Subject: [PATCH] Added an audio handler --- MediaBrowser.Api/HttpHandlers/AudioHandler.cs | 45 +++++++++++++++++++ MediaBrowser.Api/MediaBrowser.Api.csproj | 1 + MediaBrowser.Api/Plugin.cs | 6 ++- .../Net/Handlers/StaticFileHandler.cs | 2 +- 4 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 MediaBrowser.Api/HttpHandlers/AudioHandler.cs diff --git a/MediaBrowser.Api/HttpHandlers/AudioHandler.cs b/MediaBrowser.Api/HttpHandlers/AudioHandler.cs new file mode 100644 index 000000000..8ebaf04bc --- /dev/null +++ b/MediaBrowser.Api/HttpHandlers/AudioHandler.cs @@ -0,0 +1,45 @@ +using System; +using MediaBrowser.Common.Net.Handlers; +using MediaBrowser.Controller; +using MediaBrowser.Model.Entities; + +namespace MediaBrowser.Api.HttpHandlers +{ + public class AudioHandler : StaticFileHandler + { + private BaseItem _LibraryItem; + /// + /// Gets the library item that will be played, if any + /// + private BaseItem LibraryItem + { + get + { + if (_LibraryItem == null) + { + string id = QueryString["id"]; + + if (!string.IsNullOrEmpty(id)) + { + _LibraryItem = Kernel.Instance.GetItemById(Guid.Parse(id)); + } + } + + return _LibraryItem; + } + } + + public override string Path + { + get + { + if (LibraryItem != null) + { + return LibraryItem.Path; + } + + return base.Path; + } + } + } +} diff --git a/MediaBrowser.Api/MediaBrowser.Api.csproj b/MediaBrowser.Api/MediaBrowser.Api.csproj index 4560f70a1..33c209cd4 100644 --- a/MediaBrowser.Api/MediaBrowser.Api.csproj +++ b/MediaBrowser.Api/MediaBrowser.Api.csproj @@ -47,6 +47,7 @@ + diff --git a/MediaBrowser.Api/Plugin.cs b/MediaBrowser.Api/Plugin.cs index fe061a48b..02546c693 100644 --- a/MediaBrowser.Api/Plugin.cs +++ b/MediaBrowser.Api/Plugin.cs @@ -44,7 +44,7 @@ namespace MediaBrowser.Api else if (localPath.EndsWith("/api/image", StringComparison.OrdinalIgnoreCase)) { return new ImageHandler(); - } + } else if (localPath.EndsWith("/api/users", StringComparison.OrdinalIgnoreCase)) { return new UsersHandler(); @@ -89,6 +89,10 @@ namespace MediaBrowser.Api { return new StaticFileHandler(); } + else if (localPath.EndsWith("/api/audio", StringComparison.OrdinalIgnoreCase)) + { + return new AudioHandler(); + } return null; } diff --git a/MediaBrowser.Common/Net/Handlers/StaticFileHandler.cs b/MediaBrowser.Common/Net/Handlers/StaticFileHandler.cs index 9c9912152..9bffd8e59 100644 --- a/MediaBrowser.Common/Net/Handlers/StaticFileHandler.cs +++ b/MediaBrowser.Common/Net/Handlers/StaticFileHandler.cs @@ -10,7 +10,7 @@ namespace MediaBrowser.Common.Net.Handlers { public class StaticFileHandler : BaseHandler { - public string Path + public virtual string Path { get {