void Playlist_SegmentSwitched(IHLSPlaylist sender, IHLSSegmentSwitchEventArgs args)
 {
     Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
     {
         var hasme = VisualTreeHelper.FindElementsInHostCoordinates(new Point(gridMediaDisplay.ActualWidth / 2, gridMediaDisplay.ActualHeight / 2), gridMediaDisplay).
                     Where(uie => uie is MediaElement).FirstOrDefault();
         if (args.ToSegment.MediaType == TrackType.AUDIO && hasme != null) //first segment being played and audio only
         {
             SwitchTrackTypeVisual(TrackType.AUDIO);
         }
     });
 }
Exemple #2
0
 void Playlist_SegmentSwitched(IHLSPlaylist sender, IHLSSegmentSwitchEventArgs args)
 {
     _player.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
     {
         try
         {
             _data.CurrentSegment = args.ToSegment.SequenceNumber;
         }
         catch (Exception Ex)
         { }
     });
 }
        void Playlist_SegmentSwitched(IHLSPlaylist sender, IHLSSegmentSwitchEventArgs args)
        {
            try
            {
                if (_controller.Playlist.ActiveVariantStream != null && _controller.Playlist.ActiveVariantStream.Playlist != null && !_controller.Playlist.IsLive && _totalSegments == 0)
                {
                    _totalSegments = _controller.Playlist.ActiveVariantStream.Playlist.SegmentCount;
                    _player.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                    {
                        if (PropertyChanged != null)
                        {
                            PropertyChanged(this, new PropertyChangedEventArgs("TotalSegments"));
                        }
                    });
                }
                else if (!_controller.Playlist.IsMaster)
                {
                    _totalSegments = _controller.Playlist.SegmentCount;
                    _player.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                    {
                        if (PropertyChanged != null)
                        {
                            PropertyChanged(this, new PropertyChangedEventArgs("TotalSegments"));
                        }
                    });
                }

                _currentSegment = args.ToSegment.SequenceNumber;
                _player.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    if (PropertyChanged != null)
                    {
                        PropertyChanged(this, new PropertyChangedEventArgs("CurrentSegment"));
                    }
                });
            }
            catch (Exception ex)
            {
            }
        }
 void Playlist_SegmentSwitched(IHLSPlaylist sender, IHLSSegmentSwitchEventArgs args)
 {
     Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
     {
         try
         {
             var toSegment = args.ToSegment;
             if (toSegment.LoadState == SegmentState.LOADED)
             {
                 var metadatastreams = toSegment.GetMetadataStreams();
                 if (metadatastreams != null)
                 {
                     if (nometadataStatus.Visibility == Visibility.Visible)
                     {
                         nometadataStatus.Visibility = Visibility.Collapsed;
                     }
                     foreach (var stm in metadatastreams)
                     {
                         var payloads = stm.GetPayloads();
                         if (payloads != null)
                         {
                             var entry = _segmentid3tags.Where((hms) => { return(hms.StreamID == stm.StreamID); }).FirstOrDefault();
                             if (entry == null)
                             {
                                 entry = new HLSMetadataStream(stm.StreamID);
                                 _segmentid3tags.Add(entry);
                             }
                             entry.Payloads.AddRange(payloads.Select((pld) => { return(new HLSMetadataPayload(pld, args.ToBitrate, toSegment.SequenceNumber)); }));
                         }
                     }
                 }
             }
         }
         catch (Exception ex)
         {
         }
     });
 }
        void Playlist_SegmentSwitched(IHLSPlaylist sender, IHLSSegmentSwitchEventArgs args)
        {
            Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                try
                {
                    var pretaglist    = args.ToSegment.GetUnprocessedTags(UnprocessedTagPlacement.PRE);
                    var withintaglist = args.ToSegment.GetUnprocessedTags(UnprocessedTagPlacement.WITHIN);
                    UnprocessedTagForSegment tagplacement = new UnprocessedTagForSegment()
                    {
                        ForSegmentSequence = args.ToSegment.SequenceNumber
                    };
                    if (pretaglist != null && pretaglist.Count > 0)
                    {
                        tagplacement.Tags.AddRange(pretaglist);
                    }
                    if (withintaglist != null && withintaglist.Count > 0)
                    {
                        tagplacement.Tags.AddRange(withintaglist);
                    }

                    if (tagplacement.Tags.Count > 0)
                    {
                        _data.Add(tagplacement);
                    }

                    if (_data.Count > 0 && notagsStatus.Visibility == Visibility.Visible)
                    {
                        notagsStatus.Visibility = Visibility.Collapsed;
                    }
                }
                catch (Exception Ex)
                {
                }
            });
        }
    void Playlist_SegmentSwitched(IHLSPlaylist sender, IHLSSegmentSwitchEventArgs args)
    {
      Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
     {
       var hasme = VisualTreeHelper.FindElementsInHostCoordinates(new Point(gridMediaDisplay.ActualWidth / 2, gridMediaDisplay.ActualHeight / 2), gridMediaDisplay).
                                                    Where(uie => uie is MediaElement).FirstOrDefault();
       if (args.ToSegment.MediaType == TrackType.AUDIO && hasme != null) //first segment being played and audio only
         SwitchTrackTypeVisual(TrackType.AUDIO);
     });

    }
    void Playlist_SegmentSwitched(IHLSPlaylist sender, IHLSSegmentSwitchEventArgs args)
    {
      try
      {
        if (_controller.Playlist.ActiveVariantStream != null && _controller.Playlist.ActiveVariantStream.Playlist != null && !_controller.Playlist.IsLive && _totalSegments == 0)
        {
          _totalSegments = _controller.Playlist.ActiveVariantStream.Playlist.SegmentCount;
          _player.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
          {

            if (PropertyChanged != null)
            {
              PropertyChanged(this, new PropertyChangedEventArgs("TotalSegments"));
            }
          });

        }
        else if (!_controller.Playlist.IsMaster)
        {
          _totalSegments = _controller.Playlist.SegmentCount;
          _player.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
          {

            if (PropertyChanged != null)
            {
              PropertyChanged(this, new PropertyChangedEventArgs("TotalSegments"));
            }
          });
        }

        _currentSegment = args.ToSegment.SequenceNumber;
        _player.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
        {

          if (PropertyChanged != null)
          {
            PropertyChanged(this, new PropertyChangedEventArgs("CurrentSegment"));
          }
        });
      }
      catch(Exception ex)
      {

      }
    }
    void Playlist_SegmentSwitched(IHLSPlaylist sender, IHLSSegmentSwitchEventArgs args)
    {
      Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
      {
        try
        {
          var pretaglist = args.ToSegment.GetUnprocessedTags(UnprocessedTagPlacement.PRE);
          var withintaglist = args.ToSegment.GetUnprocessedTags(UnprocessedTagPlacement.WITHIN);
          UnprocessedTagForSegment tagplacement = new UnprocessedTagForSegment() { ForSegmentSequence = args.ToSegment.SequenceNumber };
          if (pretaglist != null && pretaglist.Count > 0)
            tagplacement.Tags.AddRange(pretaglist);
          if (withintaglist != null && withintaglist.Count > 0)
            tagplacement.Tags.AddRange(withintaglist);

          if (tagplacement.Tags.Count > 0)
            _data.Add(tagplacement);

          if (_data.Count > 0 && notagsStatus.Visibility == Visibility.Visible)
            notagsStatus.Visibility = Visibility.Collapsed;
        }
        catch(Exception Ex)
        {

        }

      });
    }
    /// <summary>
    /// Called when playback moves from one segment to the next. We handle it here in order to 
    /// process the 608 data that may be available.
    /// </summary>
    /// <param name="sender">The currently playing HLS media playlist</param>
    /// <param name="args">Information about the completed segment (if not at the start) and the new segment</param>
    private async void Playlist_SegmentSwitched(object sender, IHLSSegmentSwitchEventArgs args)
    {
      await this.RefreshStateAsync();
      try
      {
        // only process if app selected 608 captions
        if (ClosedCaptionType.CC608Instream == this._CaptionType)
        {
          var toSegment = args.ToSegment;

          if (TrackType.AUDIO == toSegment.MediaType)
          {
            // no need to process audio track, as it will not contain 608 caption data
            return;
          }

          var payloads = toSegment.GetInbandCCUnits();

          // no data--nothing to process
          if (null == payloads)
            return;

          // raise the event to let listeners know that we have 608 data available
          if (null != Instream608CaptionsAvailable)
            this.Instream608CaptionsAvailable(this, EventArgs.Empty);

          // copy the data to a WinRT-compatible data structure
          var map = new Dictionary<ulong, IList<Byte>>();

          foreach (var payload in payloads)
          {
            //Debug.WriteLine("Found 608 payload data for timestamp: " + payload.Timestamp.ToString() + " ticks (" + (payload.Timestamp / 10000000.0).ToString() + " sec)" );
            var rawBytes = payload.GetPayload();
            if (null != rawBytes)
            {
              var bytes = new List<byte>(rawBytes);
              ulong key = (ulong)payload.Timestamp.Ticks;
              if (map.ContainsKey(key))
                map[key] = bytes;
              else
                map.Add(key, bytes);
            }
          }

          await this._MediaPlayer.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
          {
            try
            {
              if (this._MediaPlayer.SelectedCaption != null)
              {
                // call this method on the selected caption object (if there is one)--this will in turn raise an 
                // event that the 608 caption plugin should be listening for...
                this._MediaPlayer.SelectedCaption.AugmentPayload(map, TimeSpan.Zero, TimeSpan.Zero);
              }

              // add the payload data to each caption object, in case it gets selected later
              foreach (var c in this._MediaPlayer.AvailableCaptions)
              {
                // make sure we have the queue ready--if not, create it
                var queue = c.Payload as Queue<Dictionary<ulong, IList<Byte>>>;
                if (null == queue)
                {
                  queue = new Queue<Dictionary<ulong, IList<Byte>>>();
                  c.Payload = queue;
                }

                // store the most recent data on the end of the queue
                queue.Enqueue(map);

                // but only keep the most recent three sets of data (as we could be as much as 30 seconds ahead)
                while (queue.Count > 3)
                  queue.Dequeue();
              }
            }
            catch { }
          });
        }
        else if (this._CaptionType == ClosedCaptionType.WebVTTSidecar && _WebVTTCaptions != null && _WebVTTCaptions.CurrentSubtitleId != null)
        {
          await this._MediaPlayer.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () =>
          {
            try
            {
              await _WebVTTCaptions.DownloadAllSegmentsAsync(_WebVTTCaptions.CurrentSubtitleId);
            }
            catch { }
          });
        }
      }

      catch  { }
    }
Exemple #10
0
        /// <summary>
        /// Called when playback moves from one segment to the next. We handle it here in order to
        /// process the 608 data that may be available.
        /// </summary>
        /// <param name="sender">The currently playing HLS media playlist</param>
        /// <param name="args">Information about the completed segment (if not at the start) and the new segment</param>
        private async void Playlist_SegmentSwitched(object sender, IHLSSegmentSwitchEventArgs args)
        {
            await this.RefreshStateAsync();

            try
            {
                // only process if app selected 608 captions
                if (ClosedCaptionType.CC608Instream == this._CaptionType)
                {
                    var toSegment = args.ToSegment;

                    if (TrackType.AUDIO == toSegment.MediaType)
                    {
                        // no need to process audio track, as it will not contain 608 caption data
                        return;
                    }

                    var payloads = toSegment.GetInbandCCUnits();

                    // no data--nothing to process
                    if (null == payloads)
                    {
                        return;
                    }

                    // raise the event to let listeners know that we have 608 data available
                    if (null != Instream608CaptionsAvailable)
                    {
                        this.Instream608CaptionsAvailable(this, EventArgs.Empty);
                    }

                    // copy the data to a WinRT-compatible data structure
                    var map = new Dictionary <ulong, IList <byte> >();

                    foreach (var payload in payloads)
                    {
                        //Debug.WriteLine("Found 608 payload data for timestamp: " + payload.Timestamp.ToString() + " ticks (" + (payload.Timestamp / 10000000.0).ToString() + " sec)" );
                        var rawBytes = payload.GetPayload();
                        if (null != rawBytes)
                        {
                            var   bytes = new List <byte>(rawBytes);
                            ulong key   = (ulong)payload.Timestamp.Ticks;
                            if (map.ContainsKey(key))
                            {
                                map[key] = bytes;
                            }
                            else
                            {
                                map.Add(key, bytes);
                            }
                        }
                    }

                    await this._MediaPlayer.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                    {
                        try
                        {
                            if (this._MediaPlayer.SelectedCaption != null)
                            {
                                // call this method on the selected caption object (if there is one)--this will in turn raise an
                                // event that the 608 caption plugin should be listening for...
                                this._MediaPlayer.SelectedCaption.AugmentPayload(map, TimeSpan.Zero, TimeSpan.Zero);
                            }

                            // add the payload data to each caption object, in case it gets selected later
                            foreach (var c in this._MediaPlayer.AvailableCaptions)
                            {
                                // make sure we have the queue ready--if not, create it
                                var queue = c.Payload as Queue <Dictionary <ulong, IList <byte> > >;
                                if (null == queue)
                                {
                                    queue     = new Queue <Dictionary <ulong, IList <byte> > >();
                                    c.Payload = queue;
                                }

                                // store the most recent data on the end of the queue
                                queue.Enqueue(map);

                                // but only keep the most recent three sets of data (as we could be as much as 30 seconds ahead)
                                while (queue.Count > 3)
                                {
                                    queue.Dequeue();
                                }
                            }
                        }
                        catch { }
                    });
                }
                else if (this._CaptionType == ClosedCaptionType.WebVTTSidecar && _WebVTTCaptions != null && _WebVTTCaptions.CurrentSubtitleId != null)
                {
                    await this._MediaPlayer.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() =>
                    {
                        try
                        {
                            await _WebVTTCaptions.DownloadAllSegmentsAsync(_WebVTTCaptions.CurrentSubtitleId);
                        }
                        catch { }
                    });
                }
            }

            catch  { }
        }
    void Playlist_SegmentSwitched(IHLSPlaylist sender, IHLSSegmentSwitchEventArgs args)
    {
      Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
      {
        try
        {
          var toSegment = args.ToSegment;
          if (toSegment.LoadState == SegmentState.LOADED)
          {
            var metadatastreams = toSegment.GetMetadataStreams();
            if (metadatastreams != null)
            {
              if (nometadataStatus.Visibility == Visibility.Visible)
                nometadataStatus.Visibility = Visibility.Collapsed;
              foreach (var stm in metadatastreams)
              {
                var payloads = stm.GetPayloads();
                if (payloads != null)
                {

                  var entry = _segmentid3tags.Where((hms) => { return hms.StreamID == stm.StreamID; }).FirstOrDefault();
                  if (entry == null)
                  {
                    entry = new HLSMetadataStream(stm.StreamID);
                    _segmentid3tags.Add(entry);
                  }
                  entry.Payloads.AddRange(payloads.Select((pld) => { return new HLSMetadataPayload(pld, args.ToBitrate, toSegment.SequenceNumber); }));
                }
              }
            }
          }
        }
        catch(Exception ex)
        {

        }
         
      });
    }
 void Playlist_SegmentSwitched(IHLSPlaylist sender, IHLSSegmentSwitchEventArgs args)
 {
   _player.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
   {
     try
     {
       _data.CurrentSegment = args.ToSegment.SequenceNumber; 
     }
     catch(Exception Ex)
     { }
   });
 }