/// <summary> /// Update the Caption options /// </summary> /// <param name="settings">the custom caption settings</param> private void UpdateCaptionOptions(PlayerFramework.CaptionSettings.Model.CustomCaptionSettings settings) { CC608Plugin cc608plugIn = this.MediaPlayer.Plugins.OfType <CC608Plugin>().FirstOrDefault(); if (cc608plugIn != null) { var fontFamily = GetFontFamilyName(settings.FontFamily); var captionOptions = new Microsoft.PlayerFramework.CC608.CaptionOptions { FontFamily = fontFamily == null ? string.Empty : fontFamily, FontSize = settings.FontSize.HasValue ? settings.FontSize.Value : 100, FontBrush = settings.FontColor == null ? null : new SolidColorBrush(settings.FontColor.ToColor()), BackgroundBrush = settings.BackgroundColor == null ? null : new SolidColorBrush(settings.BackgroundColor.ToColor()), VideoWidth = this.MediaPlayer.ActualWidth }; if (settings.FontFamily == PlayerFramework.CaptionSettings.Model.FontFamily.Default || settings.FontFamily == PlayerFramework.CaptionSettings.Model.FontFamily.MonospaceSansSerif || settings.FontFamily == PlayerFramework.CaptionSettings.Model.FontFamily.MonospaceSerif) { captionOptions.CaptionWidth = 0; } else { double fontSize = 100; switch (captionOptions.FontSize) { case 50: fontSize = 75; break; case 100: break; case 150: fontSize = 120; break; case 200: fontSize = 130; break; } captionOptions.CaptionWidth = fontSize * this.MediaPlayer.ActualWidth * 0.5 / 100.0; } cc608plugIn.CaptionOptions = captionOptions; } }
/// <summary> /// Detach the Caption Added event handler /// </summary> protected override void OnDeactivate() { if (this.MediaPlayer != null) { CC608Plugin cc608plugIn = this.MediaPlayer.Plugins.OfType <CC608Plugin>().FirstOrDefault(); if (cc608plugIn != null) { cc608plugIn.OnCaptionAdded -= this.OnCaptionAdded; } this.MediaPlayer.SizeChanged -= this.MediaPlayer_SizeChanged; } base.OnDeactivate(); }
/// <summary> /// Hook up the caption added even handler /// </summary> /// <returns>true if the CC608Plugin is in the MediaPlayer</returns> protected override bool OnActivate() { CC608Plugin cc608plugIn = this.MediaPlayer.Plugins.OfType <CC608Plugin>().FirstOrDefault(); if (cc608plugIn == null) { System.Diagnostics.Debug.WriteLine("You need to add the CC608PlugIn to enable 608 Caption Settings."); return(false); } cc608plugIn.OnCaptionAdded += this.OnCaptionAdded; this.MediaPlayer.SizeChanged += this.MediaPlayer_SizeChanged; return(base.OnActivate()); }