diff options
| author | LukePulverenti Luke Pulverenti luke pulverenti <LukePulverenti Luke Pulverenti luke.pulverenti@gmail.com> | 2012-09-09 09:56:04 -0400 |
|---|---|---|
| committer | LukePulverenti Luke Pulverenti luke pulverenti <LukePulverenti Luke Pulverenti luke.pulverenti@gmail.com> | 2012-09-09 09:56:04 -0400 |
| commit | 9f1a7845dd85ed83e351b5b408c3115ba95c2db8 (patch) | |
| tree | 1a76fd74302bda2a826ed8cfe1c7aeea2c1ca2ed /MediaBrowser.Api/HttpHandlers/AudioHandler.cs | |
| parent | 5525d108d301772856b4fe2901564b35a3ad6aef (diff) | |
Added GetAudioStreamUrl to ApiClient
Diffstat (limited to 'MediaBrowser.Api/HttpHandlers/AudioHandler.cs')
| -rw-r--r-- | MediaBrowser.Api/HttpHandlers/AudioHandler.cs | 50 |
1 files changed, 13 insertions, 37 deletions
diff --git a/MediaBrowser.Api/HttpHandlers/AudioHandler.cs b/MediaBrowser.Api/HttpHandlers/AudioHandler.cs index a01368635..2ce56c1fd 100644 --- a/MediaBrowser.Api/HttpHandlers/AudioHandler.cs +++ b/MediaBrowser.Api/HttpHandlers/AudioHandler.cs @@ -1,9 +1,10 @@ using MediaBrowser.Common.Net.Handlers;
+using MediaBrowser.Model.DTO;
using MediaBrowser.Model.Entities;
+using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.IO;
-using System.Linq;
using System.Net;
namespace MediaBrowser.Api.HttpHandlers
@@ -12,7 +13,7 @@ namespace MediaBrowser.Api.HttpHandlers /// Supported output formats are: mp3,flac,ogg,wav,asf,wma,aac
/// </summary>
[Export(typeof(BaseHandler))]
- public class AudioHandler : BaseMediaHandler<Audio>
+ public class AudioHandler : BaseMediaHandler<Audio, AudioOutputFormats>
{
public override bool HandlesRequest(HttpListenerRequest request)
{
@@ -20,54 +21,29 @@ namespace MediaBrowser.Api.HttpHandlers }
/// <summary>
- /// Overriding to provide mp3 as a default, since pretty much every device supports it
+ /// We can output these formats directly, but we cannot encode to them.
/// </summary>
- protected override IEnumerable<string> OutputFormats
+ protected override IEnumerable<AudioOutputFormats> UnsupportedOutputEncodingFormats
{
get
{
- IEnumerable<string> vals = base.OutputFormats;
-
- return vals.Any() ? vals : new string[] { "mp3" };
- }
- }
-
- /// <summary>
- /// We can output these files directly, but we can't encode them
- /// </summary>
- protected override IEnumerable<string> UnsupportedOutputEncodingFormats
- {
- get
- {
- return new string[] { "wma", "aac" };
+ return new AudioOutputFormats[] { AudioOutputFormats.Aac, AudioOutputFormats.Flac, AudioOutputFormats.Wav, AudioOutputFormats.Wma };
}
}
- public IEnumerable<int> AudioBitRates
+ private int? GetMaxAcceptedBitRate(AudioOutputFormats audioFormat)
{
- get
- {
- string val = QueryString["audiobitrates"];
-
- if (string.IsNullOrEmpty(val))
- {
- return new int[] { };
- }
-
- return val.Split(',').Select(v => int.Parse(v));
- }
+ return GetMaxAcceptedBitRate(audioFormat.ToString());
}
private int? GetMaxAcceptedBitRate(string audioFormat)
{
- if (!AudioBitRates.Any())
+ if (audioFormat.Equals("mp3", System.StringComparison.OrdinalIgnoreCase))
{
- return null;
+ return 320000;
}
- int index = OutputFormats.ToList().IndexOf(audioFormat);
-
- return AudioBitRates.ElementAt(index);
+ return null;
}
/// <summary>
@@ -81,7 +57,7 @@ namespace MediaBrowser.Api.HttpHandlers }
string currentFormat = Path.GetExtension(LibraryItem.Path).Replace(".", string.Empty);
-
+
int? bitrate = GetMaxAcceptedBitRate(currentFormat);
// If the bitrate is greater than our desired bitrate, we need to transcode
@@ -113,7 +89,7 @@ namespace MediaBrowser.Api.HttpHandlers {
List<string> audioTranscodeParams = new List<string>();
- string outputFormat = GetConversionOutputFormat();
+ AudioOutputFormats outputFormat = GetConversionOutputFormat();
int? bitrate = GetMaxAcceptedBitRate(outputFormat);
|
