using MediaBrowser.Common.Net.Handlers;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Model.Dto;
using System;
using System.ComponentModel.Composition;
using System.Net;
namespace MediaBrowser.Api.Streaming
{
///
/// Class HlsAudioPlaylistHandler
///
[Export(typeof(IHttpServerHandler))]
public class HlsAudioPlaylistHandler : BaseHlsPlaylistHandler
{
///
/// Handleses the request.
///
/// The request.
/// true if XXXX, false otherwise
public override bool HandlesRequest(HttpListenerRequest request)
{
return ApiService.IsApiUrlMatch("audio.m3u8", request);
}
///
/// Gets the segment file extension.
///
/// The segment file extension.
/// Only aac and mp3 audio codecs are supported.
protected override string SegmentFileExtension
{
get
{
if (AudioCodec == AudioCodecs.Aac)
{
return ".aac";
}
if (AudioCodec == AudioCodecs.Mp3)
{
return ".mp3";
}
throw new InvalidOperationException("Only aac and mp3 audio codecs are supported.");
}
}
///
/// Gets the video arguments.
///
/// System.String.
protected override string GetVideoArguments()
{
// No video
return string.Empty;
}
///
/// Gets the map args.
///
/// The map args.
protected override string MapArgs
{
get
{
return string.Format("-map 0:{0}", AudioStream.Index);
}
}
///
/// Gets the audio arguments.
///
/// System.String.
protected override string GetAudioArguments()
{
var codec = GetAudioCodec();
var args = "-codec:a " + codec;
var channels = GetNumAudioChannelsParam();
if (channels.HasValue)
{
args += " -ac " + channels.Value;
}
var sampleRate = GetSampleRateParam();
if (sampleRate.HasValue)
{
args += " -ar " + sampleRate.Value;
}
if (AudioBitRate.HasValue)
{
args += " -ab " + AudioBitRate.Value;
}
return args;
}
}
}