Esempio n. 1
0
    private async Task UpdateCaptionTracksAsync()
    {
      // can be called before the this._MediaPlayer is assigned, this is also 
      // called during MediaOpened which inits the caption track list
      if (null == this._MediaPlayer)
        return;

      await this._MediaPlayer.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () =>
      {
        if (ClosedCaptionType.CC608Instream == this._CaptionType)
        {
          this._MediaPlayer.AvailableCaptions.Clear();
          this._MediaPlayer.SelectedCaption = null;

          // MMPPF will add the "Off" option automatically when a caption track is selected

          this._MediaPlayer.AvailableCaptions.Add(new Caption() { Id = "1", Description = "CC1" });
          this._MediaPlayer.AvailableCaptions.Add(new Caption() { Id = "2", Description = "CC2" });
          this._MediaPlayer.AvailableCaptions.Add(new Caption() { Id = "3", Description = "CC3" });
          this._MediaPlayer.AvailableCaptions.Add(new Caption() { Id = "4", Description = "CC4" });

          // raise event
          if (null != this.AvailableCaptionsPopulated)
            this.AvailableCaptionsPopulated(this, EventArgs.Empty);
        } 
        else if(this._CaptionType == ClosedCaptionType.WebVTTSidecar)
        {
          try
          {
            if (this._Controller != null &&
              this._Controller.IsValid &&
              this._Controller.Playlist != null &&
              this._Controller.Playlist.IsMaster)
            {
              this._WebVTTCaptions = new HLSWebVTTCaptions(this._MediaPlayer, this._Controller);
              await this._WebVTTCaptions.UpdateCaptionOptionsAsync();

              // raise event
              if (null != this.AvailableCaptionsPopulated)
                this.AvailableCaptionsPopulated(this, EventArgs.Empty);
            }
          }
          catch { }
        }
      });
    }
Esempio n. 2
0
 /// <summary>
 /// Occurs just before the MMPPF MediaPlayer source is set, cancel any closed caption downloads for the current video.
 /// </summary>
 /// <param name="sender">MMPPF media player.</param>
 /// <param name="e">Loading data.</param>
 private void MediaPlayer_MediaLoading(object sender, MediaPlayerDeferrableEventArgs e)
 {
   if (null != this._WebVTTCaptions)
   {
     this._WebVTTCaptions.Cancel();
     this._WebVTTCaptions = null;
   }
 }
Esempio n. 3
0
    /// <summary>
    /// The selected closed caption has changed.
    /// </summary>
    /// <param name="sender">MMPPF media player.</param>
    /// <param name="e">Selected closed caption data.</param>
    private async void MediaPlayer_SelectedCaptionChanged(object sender, RoutedPropertyChangedEventArgs<Caption> e)
    {
      try
      {
        // only process for WebVTT captions
        if (ClosedCaptionType.WebVTTSidecar != this._CaptionType)
          return;

        if (null != this._WebVTTCaptions)
        {
          this._WebVTTCaptions.Cancel();
          this._WebVTTCaptions = null;
        }

        if (null != e.NewValue && this._Controller.IsValid)
        {
          this._WebVTTCaptions = new HLSWebVTTCaptions(this._MediaPlayer, _Controller);
          await this._WebVTTCaptions.DownloadAllSegmentsAsync(e.NewValue.Id);
        }
      }
      catch  { }
    }
Esempio n. 4
0
 /// <summary>
 /// Occurs when the MediaElement has closed the media source audio or video.
 /// </summary>
 /// <param name="sender">MMPPF media player.</param>
 /// <param name="e">Not used.</param>
 private void MediaPlayer_MediaClosed(object sender, RoutedEventArgs e)
 {
   if (null != this._WebVTTCaptions)
   {
     this._WebVTTCaptions.Cancel();
     this._WebVTTCaptions = null;
   }
 }