using MediaBrowser.Model.Entities;
using MediaBrowser.UI.Controls;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Windows.Controls;
namespace MediaBrowser.Plugins.DefaultTheme.Controls.Details
{
///
/// Interaction logic for MediaStreamControl.xaml
///
public partial class MediaStreamControl : BaseUserControl
{
private static readonly CultureInfo UsCulture = new CultureInfo("en-US");
///
/// Initializes a new instance of the class.
///
public MediaStreamControl()
{
InitializeComponent();
}
///
/// The _media stream
///
private MediaStream _mediaStream;
///
/// Gets or sets the media stream.
///
/// The media stream.
public MediaStream MediaStream
{
get { return _mediaStream; }
set
{
_mediaStream = value;
OnPropertyChanged("MediaStream");
OnStreamChanged();
}
}
///
/// Called when [stream changed].
///
private void OnStreamChanged()
{
if (MediaStream == null)
{
StreamName.Text = string.Empty;
StreamDetails.Children.Clear();
return;
}
var details = new List { };
if (MediaStream.Type != MediaStreamType.Video)
{
AddDetail(details, MediaStream.Language);
}
if (!string.IsNullOrEmpty(MediaStream.Path))
{
AddDetail(details, Path.GetFileName(MediaStream.Path));
}
if (MediaStream.Type == MediaStreamType.Video)
{
var resolution = string.Format("{0}*{1}", MediaStream.Width, MediaStream.Height);
AddDetail(details, resolution);
}
AddDetail(details, MediaStream.AspectRatio);
if (MediaStream.Type != MediaStreamType.Video)
{
if (MediaStream.IsDefault)
{
//AddDetail(details, "default");
}
if (MediaStream.IsForced)
{
AddDetail(details, "forced");
}
}
AddDetail(details, MediaStream.Codec);
if (MediaStream.Channels.HasValue)
{
AddDetail(details, MediaStream.Channels.Value.ToString(UsCulture) + "ch");
}
if (MediaStream.BitRate.HasValue)
{
var text = (MediaStream.BitRate.Value / 1000).ToString(UsCulture) + "kbps";
AddDetail(details, text);
}
var framerate = MediaStream.AverageFrameRate ?? MediaStream.RealFrameRate ?? 0;
if (framerate > 0)
{
AddDetail(details, framerate.ToString(UsCulture));
}
if (MediaStream.SampleRate.HasValue)
{
AddDetail(details, MediaStream.SampleRate.Value.ToString(UsCulture) + "khz");
}
AddDetail(string.Join(" \u2022 ", details.ToArray()));
StreamName.Text = MediaStream.Type.ToString();
}
private void AddDetail(string text)
{
if (string.IsNullOrEmpty(text))
{
return;
}
var control = new TextBlock() { Text = text };
control.SetResourceReference(StyleProperty, "TextBlockStyle");
StreamDetails.Children.Add(control);
}
private void AddDetail(ICollection list, string text)
{
if (string.IsNullOrEmpty(text))
{
return;
}
list.Add(text);
}
}
}