protected override FrameworkElement CreateContentsElement()
        {
            var me = new SmoothStreamingMediaElement();
#if HACKMODE
            me.Name = GetNewName();
#endif
            if (AdSource.IsScalable)
            {
                if (AdSource.MaintainAspectRatio)
                {
                    me.Stretch = Stretch.Uniform;
                }
                else
                {
                    me.Stretch = Stretch.Fill;
                }
            }
            else
            {
                me.Stretch = Stretch.None;
            }

            me.AutoPlay = false;
            me.MediaFailed += new EventHandler<ExceptionRoutedEventArgs>(OnAdPlayerMediaFailed);
            me.MediaEnded += new RoutedEventHandler(OnAdPlayerMediaEnded);
            me.MediaOpened += new RoutedEventHandler(OnAdPlayerMediaOpened);
            me.CurrentStateChanged += new RoutedEventHandler(OnAdPlayerCurrentStateChanged);
            me.ManifestReady += new EventHandler<EventArgs>(me_ManifestReady);

            return me;
        }
        public void Resume(SmoothStreamingMediaElement media)
        {
            if (media != MainMedia)
            {
                // disabling slave media
                foreach (SlaveMediaElement slave in SubMediaElements)
                {
                    if (slave.MediaElement == media)
                    {
                        slave.IsLogicalSyncEnabled = true;

                        if (slave.IsPhysicalSyncEnabled)
                        {
                            slave.MediaElement.Play();
                        }
                    }
                }
            }
            else
            {
                // disable main media
                foreach (SlaveMediaElement slave in SubMediaElements)
                {
                    slave.IsLogicalSyncEnabled = true;
                }

                MainMedia.Play();
            }
        }
        public void Suspend(SmoothStreamingMediaElement media)
        {
            if (media != MainMedia)
            {
                // disabling slave media
                foreach (SlaveMediaElement slave in SubMediaElements)
                {
                    if (slave.MediaElement == media)
                    {
                        slave.IsLogicalSyncEnabled = false;
                        try
                        {
                            slave.MediaElement.Pause();
                        }
                        catch (InvalidOperationException) { }
                    }
                }
            }
            else
            {
                // disable main media
                foreach (SlaveMediaElement slave in SubMediaElements)
                {
                    slave.IsLogicalSyncEnabled = false;
                }

                try
                {
                    MainMedia.Pause();
                }
                catch (InvalidOperationException) { }
            }
        }
Beispiel #4
0
        /// <summary>
        /// Returns the last observed DownloadTrack.Bitrate
        /// </summary>
        /// <param name="smoothStreamingMediaElement">smoothStreamingMediaElement</param>
        public ulong GetLastDownloadBitrate(SmoothStreamingMediaElement smoothStreamingMediaElement)
        {
            SSMEStateInfo ssmeStateInfo =
                GetSSMEStateInfoThrowIfNotFound(smoothStreamingMediaElement);

            return(ssmeStateInfo.LastDownloadTrackBitrate);
        }
Beispiel #5
0
 public void Dispose()
 {
     Tracing.Shutdown();
     ssme.ManifestReady        -= ssme_ManifestReady;
     ssme.PlaybackTrackChanged -= ssme_PlaybackTrackChanged;
     ssme = null;
 }
Beispiel #6
0
        /// <summary>
        /// Returns the last observed RenderedFramesPerSecond
        /// </summary>
        /// <param name="smoothStreamingMediaElement">smoothStreamingMediaElement</param>
        public double GetAverageRenderedFramesPerSecond(SmoothStreamingMediaElement smoothStreamingMediaElement)
        {
            SSMEStateInfo ssmeStateInfo =
                GetSSMEStateInfoThrowIfNotFound(smoothStreamingMediaElement);

            return(ssmeStateInfo.AverageRenderedFramesPerSecond);
        }
Beispiel #7
0
        /// <summary>
        /// GetMinimumPlaybackBitrate - gets the bitrate set during the call to SetMinimumPlaybackBitrate
        /// </summary>
        /// <param name="smoothStreamingMediaElement">smoothStreamingMediaElement</param>
        public ulong GetMinimumPlaybackBitrate(SmoothStreamingMediaElement smoothStreamingMediaElement)
        {
            SSMEStateInfo ssmeStateInfo =
                GetSSMEStateInfoThrowIfNotFound(smoothStreamingMediaElement);

            return(ssmeStateInfo.MinimumPlaybackBitrate);
        }
Beispiel #8
0
        /// <summary>
        /// Picks a thumbnail of the current media element.
        /// </summary>
        /// <param name="mediaData">The media data o the current element.</param>
        public void PickThumbnail(MediaData mediaData)
        {
            if (mediaData != null)
            {
                SmoothStreamingMediaElement mediaElement = mediaData.Media as SmoothStreamingMediaElement;

                if (mediaElement != null)
                {
                    this.StartThumbnailBuffer();
                    bool     thumbnailSeekCompleted = false;
                    TimeSpan currentPosition        = mediaElement.Position;

                    CoreSmoothStreamingMediaElement thumbnailMediaElement = new CoreSmoothStreamingMediaElement
                    {
                        Width    = mediaElement.ActualWidth,
                        Height   = mediaElement.ActualHeight,
                        IsMuted  = true,
                        AutoPlay = false,
                        Volume   = 0,
                    };

                    DispatcherTimer thubmnailTimer = new DispatcherTimer {
                        Interval = new TimeSpan(0, 0, 0, 5)
                    };

                    thubmnailTimer.Tick += (sender, e) =>
                    {
                        if (thumbnailSeekCompleted)
                        {
                            thumbnailSeekCompleted = false;
                            thubmnailTimer.Stop();
                            WriteableBitmap writeableBitmap = new WriteableBitmap(thumbnailMediaElement, null);

                            // writeableBitmap.Render(mediaElement, null);
                            writeableBitmap.Invalidate();
                            this.Model.SetThumbnail(writeableBitmap);
                            this.PlayerContainerGrid.Children.Remove(thumbnailMediaElement);
                            thumbnailMediaElement = null;
                            thubmnailTimer        = null;
                            this.EndThumbnailBuffer();
                        }
                    };

                    thubmnailTimer.Start();

                    this.PlayerContainerGrid.Children.Add(thumbnailMediaElement);

                    thumbnailMediaElement.ManifestReady += (sender, e) => ((CoreSmoothStreamingMediaElement)sender).SelectMaxAvailableBitrateTracks("cameraAngle", "camera1");

                    thumbnailMediaElement.MediaOpened += (sender, e) =>
                    {
                        ((SmoothStreamingMediaElement)sender).Position       = currentPosition;
                        ((CoreSmoothStreamingMediaElement)sender).Visibility = Visibility.Collapsed;
                    };

                    thumbnailMediaElement.SeekCompleted        += (sender, e) => thumbnailSeekCompleted = true;
                    thumbnailMediaElement.SmoothStreamingSource = mediaElement.SmoothStreamingSource;
                }
            }
        }
Beispiel #9
0
        /// <summary>
        /// Create a new player, removing the old one if needed.
        /// </summary>
        private void PreparePlayer()
        {
            if (MediaPlayer != null)
            {
                Children.Remove(MediaPlayer);
            }

            MediaPlayer        = new SmoothStreamingMediaElement();
            MediaPlayer.Volume = 0.9;
            Children.Insert(0, MediaPlayer);

            MediaPlayer.CurrentStateChanged      += MediaPlayer_StateChange;
            MediaPlayer.MediaOpened              += MediaPlayer_MediaOpened;
            MediaPlayer.MediaEnded               += MediaPlayer_MediaEnded;
            MediaPlayer.ClipStateChanged         += MediaPlayer_PlaybackStateChange;
            MediaPlayer.MarkerReached            += MediaPlayer_MarkerReached;
            MediaPlayer.BufferingProgressChanged += MediaPlayer_BufferingProgressChanged;
            MediaPlayer.ClipError += MediaPlayer_ClipError;
            MediaPlayer.SmoothStreamingErrorOccurred += MediaPlayer_SmoothStreamingErrorOccurred;


            if (CurrentPlaylist != null)
            {
                MediaPlayer.Stretch   = CurrentPlaylist.StretchMode;
                MediaPlayer.CacheMode = (CurrentPlaylist.EnableCachedComposition && (MediaPlayer.CacheMode == null)) ? new BitmapCache() : null;
            }
            else
            {
                MediaPlayer.Stretch = Stretch.Uniform;
            }
        }
        protected override FrameworkElement CreateContentsElement()
        {
            var me = new SmoothStreamingMediaElement();

#if HACKMODE
            me.Name = GetNewName();
#endif
            if (AdSource.IsScalable)
            {
                if (AdSource.MaintainAspectRatio)
                {
                    me.Stretch = Stretch.Uniform;
                }
                else
                {
                    me.Stretch = Stretch.Fill;
                }
            }
            else
            {
                me.Stretch = Stretch.None;
            }

            me.AutoPlay             = false;
            me.MediaFailed         += new EventHandler <ExceptionRoutedEventArgs>(OnAdPlayerMediaFailed);
            me.MediaEnded          += new RoutedEventHandler(OnAdPlayerMediaEnded);
            me.MediaOpened         += new RoutedEventHandler(OnAdPlayerMediaOpened);
            me.CurrentStateChanged += new RoutedEventHandler(OnAdPlayerCurrentStateChanged);
            me.ManifestReady       += new EventHandler <EventArgs>(me_ManifestReady);

            return(me);
        }
Beispiel #11
0
        /// <summary>
        /// Removes a SmoothStreamingMediaElement
        /// </summary>
        /// <param name="smoothStreamingMediaElement">smoothStreamingMediaElement</param>
        public void RemoveSmoothStreamingMediaElement(SmoothStreamingMediaElement smoothStreamingMediaElement)
        {
            SSMEStateInfo ssmeStateInfo =
                GetSSMEStateInfoThrowIfNotFound(smoothStreamingMediaElement);

            UnhookEvents(ssmeStateInfo.SmoothStreamingMediaElement);
            _ssmeStateInfoList.Remove(ssmeStateInfo);
        }
Beispiel #12
0
        /// <summary>
        /// SetMinimumPlaybackBitrate
        /// </summary>
        /// <param name="smoothStreamingMediaElement">smoothStreamingMediaElement</param>
        /// <param name="minimumPlaybackBitrate">
        ///     The minimum bitrate (in bps) this SmoothStreamingMediaElement
        ///     must be capable of playing before the next SmoothStreamingMediaElement
        ///     should be enabled
        /// </param>
        public void SetMinimumPlaybackBitrate(SmoothStreamingMediaElement smoothStreamingMediaElement,
                                              ulong minimumPlaybackBitrate)
        {
            SSMEStateInfo ssmeStateInfo =
                GetSSMEStateInfoThrowIfNotFound(smoothStreamingMediaElement);

            ssmeStateInfo.MinimumPlaybackBitrate = minimumPlaybackBitrate;
        }
 public LinearAdContext(ClipContext clipContext, SmoothStreamingMediaElement ssme)
     : base(clipContext)
 {
     if (ssme == null)
     {
         throw new ArgumentNullException("ssme");
     }
     _ssme = ssme;
 }
 internal LinearAdContext(ScheduledAd scheduledAd, SmoothStreamingMediaElement ssme, object data)
     : base(scheduledAd, data)
 {
     if (ssme == null)
     {
         throw new ArgumentNullException("ssme");
     }
     _ssme = ssme;
 }
 /// <summary>
 /// Disconnects the SmoothStreamingMediaElement that was passed to the Attach method
 /// </summary>
 public void Detach()
 {
     TraceMonitor.Stop();
     DetachEvents();
     if (agent != null)
     {
         agent.Dispose();
     }
     mediaElement = null;
 }
 private string GetTimelineString(SmoothStreamingMediaElement ssme)
 {
     string str = "";
     TimeSpan span = ssme.StartPosition.Add(TimeSpan.FromSeconds(-30.0));
     for (int i = 0; i < 90; i++)
     {
         long totalSeconds = (long) span.TotalSeconds;
         if ((totalSeconds - ((long) ssme.StartPosition.TotalSeconds)) == 0L)
         {
             str = str + "S";
         }
         if ((totalSeconds - ((long) ssme.Position.TotalSeconds)) == 0L)
         {
             str = str + "P";
         }
         if ((totalSeconds - ((long) ssme.EndPosition.TotalSeconds)) == 0L)
         {
             str = str + "E";
         }
         if ((totalSeconds - ((long) ssme.LivePosition)) == 0L)
         {
             str = str + "L";
         }
         else
         {
             str = str + "-";
         }
         span = span.Add(TimeSpan.FromSeconds(1.0));
     }
     if (((ssme.ManifestInfo != null) && (ssme.ManifestInfo.Segments != null)) && ssme.ManifestInfo.Segments.Any<SegmentInfo>())
     {
         foreach (StreamInfo info in ssme.ManifestInfo.Segments.First<SegmentInfo>().SelectedStreams)
         {
             if (info.Attributes["type"] == "video")
             {
                 str = str + " | " + info.Attributes["type"] + " ";
                 foreach (TrackInfo info2 in info.AvailableTracks)
                 {
                     bool flag = ssme.VideoPlaybackTrack == info2;
                     if (flag)
                     {
                         str = str + "[";
                     }
                     str = str + info2.Bitrate;
                     if (flag)
                     {
                         str = str + "]";
                     }
                     str = str + " ";
                 }
             }
         }
     }
     return str;
 }
        protected override void OnMediaOpened()
        {
            base.OnMediaOpened();

            SmoothStreamingMediaElement ssme = ActiveMediaPlugin.VisualElement as SmoothStreamingMediaElement;

            if (ssme != null)
            {
                MessageBox.Show("Accessed the SmoothStreamingMediaElement");
            }
        }
Beispiel #18
0
        /// <summary>
        /// SetMinimumRenderedFramesPerSecond specifies the minimum RenderedFramesPerSecond
        /// each SmoothStreamingMediaElement should sustain before the next
        /// SmoothStreamingMediaElement is enabled
        /// </summary>
        /// <param name="smoothStreamingMediaElement">smoothStreamingMediaElement</param>
        /// <param name="minimumRenderedFramesPerSecond">minimumRenderedFramesPerSecond</param>
        public void SetMinimumRenderedFramesPerSecond(SmoothStreamingMediaElement smoothStreamingMediaElement,
                                                      double minimumRenderedFramesPerSecond)
        {
            if (minimumRenderedFramesPerSecond < 0.0)
            {
                throw new ArgumentOutOfRangeException("minimumRenderedFramesPerSecond");
            }
            SSMEStateInfo ssmeStateInfo =
                GetSSMEStateInfoThrowIfNotFound(smoothStreamingMediaElement);

            ssmeStateInfo.MinimumRenderedFramesPerSecond = minimumRenderedFramesPerSecond;
        }
        public AdaptiveMonitor(SmoothStreamingMediaElement ssme, string tracingConfigPath)
        {
            this.ssme = ssme;
            ssme.PlaybackTrackChanged += ssme_PlaybackTrackChanged;
            ssme.ManifestReady += ssme_ManifestReady;

            Tracing.Initialize();
            using (var reader = System.Xml.XmlReader.Create(tracingConfigPath))
            {
                Tracing.ReadTraceConfig(reader);
            }
        }
Beispiel #20
0
 /// <summary>
 /// Simple helper to see if we have an id
 /// </summary>
 private bool ContainsSmoothStreamingMediaElement(SmoothStreamingMediaElement smoothStreamingMediaElement)
 {
     for (int i = 0; i < _ssmeStateInfoList.Count; i++)
     {
         if (ReferenceEquals(_ssmeStateInfoList[i].SmoothStreamingMediaElement,
                             smoothStreamingMediaElement))
         {
             return(true);
         }
     }
     return(false);
 }
Beispiel #21
0
        public AdaptiveMonitor(SmoothStreamingMediaElement ssme, string tracingConfigPath)
        {
            this.ssme = ssme;
            ssme.PlaybackTrackChanged += ssme_PlaybackTrackChanged;
            ssme.ManifestReady        += ssme_ManifestReady;

            Tracing.Initialize();
            using (var reader = System.Xml.XmlReader.Create(tracingConfigPath))
            {
                Tracing.ReadTraceConfig(reader);
            }
        }
Beispiel #22
0
        /// <summary>
        /// GetSSMEStateInfoThrowIfNotFound
        /// </summary>
        /// <param name="smoothStreamingMediaElement">smoothStreamingMediaElement</param>
        private SSMEStateInfo GetSSMEStateInfoThrowIfNotFound(SmoothStreamingMediaElement smoothStreamingMediaElement)
        {
            SSMEStateInfo ssmeStateInfo = GetSSMEStateInfoBySSME(smoothStreamingMediaElement);

            if (ssmeStateInfo == null)
            {
                throw new ArgumentException(
                          "smoothStreamingMediaElement is not known to this MultiSmoothStreamingMediaElementHeuristicsManager",
                          "smoothStreamingMediaElement");
            }
            return(ssmeStateInfo);
        }
Beispiel #23
0
 /// <summary>
 /// Simple helper to see if we have an SSME
 /// </summary>
 private SSMEStateInfo GetSSMEStateInfoBySSME(SmoothStreamingMediaElement smoothStreamingMediaElement)
 {
     for (int i = 0; i < _ssmeStateInfoList.Count; i++)
     {
         if (ReferenceEquals(_ssmeStateInfoList[i].SmoothStreamingMediaElement,
                             smoothStreamingMediaElement))
         {
             return(_ssmeStateInfoList[i]);
         }
     }
     return(null);
 }
 public void EnableSync(SmoothStreamingMediaElement slave)
 {
     if (slave != null)
     {
         foreach (SlaveMediaElement video in SubMediaElements)
         {
             if (video.MediaElement != null && video.MediaElement == slave)
             {
                 video.IsLogicalSyncEnabled = true;
                 break;
             }
         }
     }
 }
Beispiel #25
0
        protected override void OnMediaPluginLoaded()
        {
            base.OnMediaPluginLoaded();

            ssme = ActiveMediaPlugin.VisualElement as SmoothStreamingMediaElement;

            if (ssme != null)
            {
                ssme.MediaFailed += new EventHandler<ExceptionRoutedEventArgs>(SmoothPlayer_MediaFailed);
                ssme.SmoothStreamingErrorOccurred += new EventHandler<SmoothStreamingErrorEventArgs>(SmoothPlayer_SmoothStreamingErrorOccurred);
                ssme.ClipError += new EventHandler<ClipEventArgs>(SmoothPlayer_ClipError);
            }

        }
 public void EnableSync(SmoothStreamingMediaElement slave)
 {
     if (slave != null)
     {
         foreach (SlaveMediaElement video in SubMediaElements)
         {
             if (video.MediaElement != null && video.MediaElement == slave)
             {
                 video.IsLogicalSyncEnabled = true;
                 break;
             }
         }
     }
 }
        public SmoothStreamingElement(SmoothStreamingMediaElement element)
        {
            this.element = element;
            this.element.CurrentStateChanged      += element_CurrentStateChanged;
            this.element.BufferingProgressChanged += element_BufferingProgressChanged;
            this.element.DownloadProgressChanged  += element_DownloadProgressChanged;

            this.element.MediaEnded        += element_MediaEnded;
            this.element.MediaFailed       += element_MediaFailed;
            this.element.MediaOpened       += element_MediaOpened;
            this.element.MouseLeftButtonUp += element_MouseLeftButtonUp;

            this.element.PlaybackTrackChanged += element_PlaybackTrackChanged;
            this.element.ManifestReady        += element_ManifestReady;
        }
        /// <summary>
        /// Initializes the smooth streaming media element.
        /// </summary>
        /// <param name="ssme">The instance of the SmoothStreamingMediaElement to use</param>
        public void Initialize(SmoothStreamingMediaElement ssme)
        {
            SSME = ssme;
            if (downloaderPlugin != null)
            {
                SSME.SmoothStreamingCache = new DownloaderPluginAdapter(downloaderPlugin);
            }

#if !WINDOWS_PHONE
            _chunkDownloadManager = new ChunkDownloadManager(SSME);
            _chunkDownloadManager.DownloadCompleted += ChunkDownloadManager_ChunkDownloadCompleted;
            _chunkDownloadManager.RetryingDownload += ChunkDownloadManager_RetryingChunkDownload;
            _chunkDownloadManager.DownloadExceededMaximumRetries += ChunkDownloadManager_ChunkDownloadExceededMaximumRetryAttempts;
#endif
            WireSmoothEvents();
        }
Beispiel #29
0
        /// <summary>
        /// Initializes the smooth streaming media element.
        /// </summary>
        /// <param name="ssme">The instance of the SmoothStreamingMediaElement to use</param>
        public void Initialize(SmoothStreamingMediaElement ssme)
        {
            SSME = ssme;
            if (downloaderPlugin != null)
            {
                SSME.SmoothStreamingCache = new DownloaderPluginAdapter(downloaderPlugin);
            }

#if !WINDOWS_PHONE
            _chunkDownloadManager = new ChunkDownloadManager(SSME);
            _chunkDownloadManager.DownloadCompleted += ChunkDownloadManager_ChunkDownloadCompleted;
            _chunkDownloadManager.RetryingDownload  += ChunkDownloadManager_RetryingChunkDownload;
            _chunkDownloadManager.DownloadExceededMaximumRetries += ChunkDownloadManager_ChunkDownloadExceededMaximumRetryAttempts;
#endif
            WireSmoothEvents();
        }
        public SmoothStreamingElement(SmoothStreamingMediaElement element)
        {
            this.element = element;
            this.element.CurrentStateChanged += element_CurrentStateChanged;
            this.element.BufferingProgressChanged += element_BufferingProgressChanged;
            this.element.DownloadProgressChanged += element_DownloadProgressChanged;

            this.element.MediaEnded += element_MediaEnded;
            this.element.MediaFailed += element_MediaFailed;
            this.element.MediaOpened += element_MediaOpened;
            this.element.MouseLeftButtonUp += element_MouseLeftButtonUp;

             this.element.PlaybackTrackChanged += element_PlaybackTrackChanged;
            this.element.ManifestReady += element_ManifestReady;

        }
Beispiel #31
0
        /// <summary>
        /// Detaches the SmoothStreamingMediaElement from the diagnostic component.
        /// It is recommended that you do not call this directly and instead use DetachFromSMF
        /// </summary>
        internal void DetachFromMediaElement()
        {
            ssme.Unloaded -= ssme_Unloaded;
            if (healthMonitor != null)
            {
                healthMonitor.Flush();
            }

            healthMonitorLogger.DetachMonitor();
            if (healthMonitor != null)
            {
                healthMonitor.Detach();
                healthMonitor = null;
            }
            ssme       = null;
            IsAttached = false;
        }
Beispiel #32
0
        /// <summary>
        /// AddSmoothStreamingMediaElement
        /// </summary>
        /// <param name="smoothStreamingMediaElement">the SmoothStreamingMediaElement</param>
        /// <param name="minimumPlaybackBitrate">
        ///     The minimum bitrate (in bps) this SmoothStreamingMediaElement
        ///     must be capable of playing before the next SmoothStreamingMediaElement
        ///     should be enabled
        /// </param>
        /// <param name="minimumRenderedFramesPerSecond">
        ///     The minimum RenderedFramesPerSecond this SmoothStreamingMediaElement
        ///     must be achieving at the minimum bitrate before the next
        ///     SmoothStreamingMediaElement should be enabled
        /// </param>
        public void AddSmoothStreamingMediaElement(SmoothStreamingMediaElement smoothStreamingMediaElement,
                                                   ulong minimumPlaybackBitrate,
                                                   double minimumRenderedFramesPerSecond)
        {
            if (ContainsSmoothStreamingMediaElement(smoothStreamingMediaElement))
            {
                throw new ArgumentException("SmoothStreamingMediaElement has already been added",
                                            "smoothStreamingMediaElement");
            }
            if (smoothStreamingMediaElement == null)
            {
                throw new ArgumentNullException("smoothStreamingMediaElement");
            }
            if (minimumRenderedFramesPerSecond < 0.0)
            {
                throw new ArgumentOutOfRangeException("minimumRenderedFramesPerSecond");
            }

            //finally, add to our collection
            var ssmeStateInfo = new SSMEStateInfo();

            ssmeStateInfo.SmoothStreamingMediaElement    = smoothStreamingMediaElement;
            ssmeStateInfo.MinimumPlaybackBitrate         = minimumPlaybackBitrate;
            ssmeStateInfo.MinimumRenderedFramesPerSecond = minimumRenderedFramesPerSecond;

            // TODOL: workaround to get the initial download and playback bitrates,
            // this can be removed when the SSME control exposes the properties
            SmoothStreamingMediaElement coreSmoothStreamingMediaElement = smoothStreamingMediaElement;

            if (coreSmoothStreamingMediaElement != null)
            {
                ssmeStateInfo.LastDownloadTrackBitrate = coreSmoothStreamingMediaElement.VideoDownloadTrack != null
                                                             ? coreSmoothStreamingMediaElement.VideoDownloadTrack.
                                                         Bitrate
                                                             : 0;
                ssmeStateInfo.LastPlaybackTrackBitrate = coreSmoothStreamingMediaElement.VideoPlaybackTrack != null
                                                             ? coreSmoothStreamingMediaElement.VideoPlaybackTrack.
                                                         Bitrate
                                                             : 0;
            }

            _ssmeStateInfoList.Add(ssmeStateInfo);

            HookEvents(smoothStreamingMediaElement);
        }
        /// <summary>
        /// AddSmoothStreamingMediaElement
        /// </summary>
        /// <param name="smoothStreamingMediaElement">the SmoothStreamingMediaElement</param>
        /// <param name="minimumPlaybackBitrate">
        ///     The minimum bitrate (in bps) this SmoothStreamingMediaElement
        ///     must be capable of playing before the next SmoothStreamingMediaElement
        ///     should be enabled
        /// </param>
        /// <param name="minimumRenderedFramesPerSecond">
        ///     The minimum RenderedFramesPerSecond this SmoothStreamingMediaElement
        ///     must be achieving at the minimum bitrate before the next 
        ///     SmoothStreamingMediaElement should be enabled
        /// </param>
        public void AddSmoothStreamingMediaElement(SmoothStreamingMediaElement smoothStreamingMediaElement,
                                                   ulong minimumPlaybackBitrate,
                                                   double minimumRenderedFramesPerSecond)
        {
            if (ContainsSmoothStreamingMediaElement(smoothStreamingMediaElement))
            {
                throw new ArgumentException("SmoothStreamingMediaElement has already been added",
                                            "smoothStreamingMediaElement");
            }
            if (smoothStreamingMediaElement == null)
            {
                throw new ArgumentNullException("smoothStreamingMediaElement");
            }
            if (minimumRenderedFramesPerSecond < 0.0)
            {
                throw new ArgumentOutOfRangeException("minimumRenderedFramesPerSecond");
            }

            //finally, add to our collection
            var ssmeStateInfo = new SSMEStateInfo();
            ssmeStateInfo.SmoothStreamingMediaElement = smoothStreamingMediaElement;
            ssmeStateInfo.MinimumPlaybackBitrate = minimumPlaybackBitrate;
            ssmeStateInfo.MinimumRenderedFramesPerSecond = minimumRenderedFramesPerSecond;

            // TODOL: workaround to get the initial download and playback bitrates,
            // this can be removed when the SSME control exposes the properties
            SmoothStreamingMediaElement coreSmoothStreamingMediaElement = smoothStreamingMediaElement;
            if (coreSmoothStreamingMediaElement != null)
            {
                ssmeStateInfo.LastDownloadTrackBitrate = coreSmoothStreamingMediaElement.VideoDownloadTrack != null
                                                             ? coreSmoothStreamingMediaElement.VideoDownloadTrack.
                                                                   Bitrate
                                                             : 0;
                ssmeStateInfo.LastPlaybackTrackBitrate = coreSmoothStreamingMediaElement.VideoPlaybackTrack != null
                                                             ? coreSmoothStreamingMediaElement.VideoPlaybackTrack.
                                                                   Bitrate
                                                             : 0;
            }

            _ssmeStateInfoList.Add(ssmeStateInfo);

            HookEvents(smoothStreamingMediaElement);
        }
        /// <summary>
        /// Connects a SmoothStreamingMediaElement that needs to be monitored
        /// </summary>
        public void Attach(SmoothStreamingMediaElement smoothStreamingMediaElement)
        {
            if (smoothStreamingMediaElement == null)
            {
                throw new ArgumentNullException("smoothStreamingMediaElement");
            }

            mediaElement = smoothStreamingMediaElement;
            if (!string.IsNullOrEmpty(mediaElement.Name))   // this allows TraceMonitor events to be filtered so we only capture ones associated with this instance of the SSME
            {
                mediaElementId = mediaElement.Name;
            }
            else
            {
                mediaElementId = GetMediaElementId();
            }

            AttachEvents();
            TraceMonitor.Start();
        }
Beispiel #35
0
        /// <summary>Override of Player Media Plugin Loaded event to address ADK issue.
        /// </summary>
        protected override void OnMediaPluginLoaded()
        {
            base.OnMediaPluginLoaded();

            if (MediaPresenterElement != null && MediaPresenterElement.Content != null)
            {
                if (MediaPresenterElement.Content is MediaElement)
                {
                    MediaElement me = MediaPresenterElement.Content as MediaElement;
                    me.HorizontalAlignment = HorizontalAlignment.Center;
                    me.VerticalAlignment   = VerticalAlignment.Center;
                }
                else if (MediaPresenterElement.Content is SmoothStreamingMediaElement)
                {
                    SmoothStreamingMediaElement ssme = MediaPresenterElement.Content as SmoothStreamingMediaElement;

                    Grid grid = VisualTreeHelper.GetChild(ssme, 0) as Grid;
                    if (grid != null)
                    {
                        MediaElement me = grid.Children[0] as MediaElement;
                        if (me != null)
                        {
                            me.VerticalAlignment   = VerticalAlignment.Center;
                            me.HorizontalAlignment = HorizontalAlignment.Center;
                        }
                        else
                        {
                            //RefAppLogging.Logger.Log("Failed to find MediaElement. Possible change in SSME Template");
                        }
                    }
                    else
                    {
                        //RefAppLogging.Logger.Log("Failed to find Grid. Possible change in SSME Template");
                    }
                }
                else
                {
                    //RefAppLogging.Logger.Log("Failed to get references to MediaPresenterElement and Content.  Possible change in Player.");
                }
            }
        }
        public void RegisterMaster(SmoothStreamingMediaElement media, TimeSpan position)
        {
            UnhookEvents();

            //MainMedia is for syncing
            //HeuristicsMasterMedia is used for Heuristics
            MainMedia = media;
            //MainMedia.Position = position;

            HookEvents();

            //UpdateSlaves();

            if (media == HeuristicMasterMedia)
            {
                HeuristicManager.StartMonitoring();
            }
            else
            {
                HeuristicManager.StopMonitoring();
            }
        }
Beispiel #37
0
        /// <summary>
        /// Attaches the SmoothStreamingMediaElement to the diagnostic component so it can be monitored.
        /// It is recommended that you do not call this directly and instead use AttachToSMF
        /// </summary>
        /// <param name="element">An instance of SSME</param>
        internal void AttachToMediaElement(SmoothStreamingMediaElement element)
        {
            // clean up the old media element just in case
            if (IsAttached)
            {
                DetachFromMediaElement();
            }

            // start logging agent if it hasn't been already
            if (!LoggingService.Current.IsSessionStarted)
            {
                LoggingService.Current.StartSession();
            }

            ssme           = element;
            ssme.Unloaded += ssme_Unloaded;

            healthMonitor = new HealthMonitor(DiagConfig);
            healthMonitor.Attach(ssme);
            healthMonitorLogger.AttachMonitor(healthMonitor);

            IsAttached = true;
        }
        protected override void DisposeDisplayControl()
        {
            if (mediaElement != null)
            {
                mediaElement.CurrentStateChanged -= OnCurrentStateChanged;
                mediaElement.BufferingProgressChanged -= OnBufferingProgressChanged;
                mediaElement.DownloadProgressChanged -= OnDownloadProgressChanged;
                mediaElement.MediaOpened -= OnMediaOpened;
                mediaElement.MediaEnded -= OnMediaEnded;

                ClearSourceBinding();

                mediaElement.ClearValue(SmoothStreamingMediaElement.IsMutedProperty);
                mediaElement.ClearValue(SmoothStreamingMediaElement.VolumeProperty);
                mediaElement.ClearValue(SmoothStreamingMediaElement.AutoPlayProperty);
            }
            mediaElement = null;
        }
        protected override object CreateDisplayControl()
        {
            mediaElement = CreateMediaElement();
            mediaElement.EnableGPUAcceleration = true;
            mediaElement.CurrentStateChanged += mediaElement_CurrentStateChanged;
            mediaElement.BufferingProgressChanged += mediaElement_BufferingProgressChanged;
            mediaElement.DownloadProgressChanged += mediaElement_DownloadProgressChanged;
            mediaElement.MediaOpened += OnMediaOpened;
            mediaElement.MediaEnded += OnMediaEnded;
            mediaElement.MediaFailed += new EventHandler<ExceptionRoutedEventArgs>(mediaElement_MediaFailed);
            mediaElement.DownloadTrackChanged += new EventHandler<TrackChangedEventArgs>(mediaElement_DownloadTrackChanged);
            mediaElement.DurationExtended += new EventHandler<DurationExtendedEventArgs>(mediaElement_DurationExtended);
            mediaElement.PlaybackTrackChanged += new EventHandler<TrackChangedEventArgs>(mediaElement_PlaybackTrackChanged);
            ISmoothVideoItem svi = CurrentItem as ISmoothVideoItem;
            if (svi != null && svi.JoinLive)
            {
                mediaElement.LivePlaybackStartPosition = PlaybackStartPosition.End;
            }

            AssignSourceBinding();

            mediaElement.SetBinding(SmoothStreamingMediaElement.IsMutedProperty, new System.Windows.Data.Binding("Controller.IsMuted") { Source = this });
            mediaElement.SetBinding(SmoothStreamingMediaElement.VolumeProperty, new System.Windows.Data.Binding("Controller.Volume") { Source = this });
            mediaElement.SetBinding(SmoothStreamingMediaElement.AutoPlayProperty, new System.Windows.Data.Binding("Controller.AutoPlay") { Source = this });

            return mediaElement;
        }
        /// <summary>
        /// Detaches the SmoothStreamingMediaElement from the diagnostic component.
        /// It is recommended that you do not call this directly and instead use DetachFromSMF
        /// </summary>
        internal void DetachFromMediaElement()
        {
            ssme.Unloaded -= ssme_Unloaded;
            if (healthMonitor != null) 
            {
                healthMonitor.Flush();
            }

            healthMonitorLogger.DetachMonitor();
            if (healthMonitor != null)
            {
                healthMonitor.Detach();
                healthMonitor = null;
            }
            ssme = null;
            IsAttached = false;
        }
        public void RegisterMaster(SmoothStreamingMediaElement media, TimeSpan position)
        {
            UnhookEvents();

            //MainMedia is for syncing
            //HeuristicsMasterMedia is used for Heuristics
            MainMedia = media;
            //MainMedia.Position = position;

            HookEvents();

            //UpdateSlaves();

            if (media == HeuristicMasterMedia)
            {
                HeuristicManager.StartMonitoring();
            }
            else
            {
                HeuristicManager.StopMonitoring();
            }
        }
 /// <summary>
 /// AddSmoothStreamingMediaElement
 /// </summary>
 /// <param name="smoothStreamingMediaElement">the SmoothStreamingMediaElement</param>
 public void AddSmoothStreamingMediaElement(SmoothStreamingMediaElement smoothStreamingMediaElement)
 {
     AddSmoothStreamingMediaElement(smoothStreamingMediaElement, 0, 0.0);
 }
        public void Suspend(SmoothStreamingMediaElement media)
        {
            if (media != MainMedia)
            {
                // disabling slave media
                foreach (SlaveMediaElement slave in SubMediaElements)
                {
                    if (slave.MediaElement == media)
                    {
                        slave.IsLogicalSyncEnabled = false;
                        try
                        {
                            slave.MediaElement.Pause();
                        }
                        catch (InvalidOperationException) { }
                    }
                }
            }
            else
            {
                // disable main media
                foreach (SlaveMediaElement slave in SubMediaElements)
                {
                    slave.IsLogicalSyncEnabled = false;
                }

                try
                {
                    MainMedia.Pause();
                }
                catch (InvalidOperationException) { }
            }
        }
 /// <summary>
 /// Simple helper to see if we have an SSME 
 /// </summary>
 private SSMEStateInfo GetSSMEStateInfoBySSME(SmoothStreamingMediaElement smoothStreamingMediaElement)
 {
     for (int i = 0; i < _ssmeStateInfoList.Count; i++)
     {
         if (ReferenceEquals(_ssmeStateInfoList[i].SmoothStreamingMediaElement,
                             smoothStreamingMediaElement))
         {
             return _ssmeStateInfoList[i];
         }
     }
     return null;
 }
 /// <summary>
 /// Simple helper to see if we have an id 
 /// </summary>
 private bool ContainsSmoothStreamingMediaElement(SmoothStreamingMediaElement smoothStreamingMediaElement)
 {
     for (int i = 0; i < _ssmeStateInfoList.Count; i++)
     {
         if (ReferenceEquals(_ssmeStateInfoList[i].SmoothStreamingMediaElement,
                             smoothStreamingMediaElement))
         {
             return true;
         }
     }
     return false;
 }
 /// <summary>
 /// GetMinimumPlaybackBitrate - gets the bitrate set during the call to SetMinimumPlaybackBitrate
 /// </summary>
 /// <param name="smoothStreamingMediaElement">smoothStreamingMediaElement</param>
 public ulong GetMinimumPlaybackBitrate(SmoothStreamingMediaElement smoothStreamingMediaElement)
 {
     SSMEStateInfo ssmeStateInfo =
         GetSSMEStateInfoThrowIfNotFound(smoothStreamingMediaElement);
     return ssmeStateInfo.MinimumPlaybackBitrate;
 }
 /// <summary>
 /// SetMinimumRenderedFramesPerSecond specifies the minimum RenderedFramesPerSecond
 /// each SmoothStreamingMediaElement should sustain before the next  
 /// SmoothStreamingMediaElement is enabled
 /// </summary>
 /// <param name="smoothStreamingMediaElement">smoothStreamingMediaElement</param>
 /// <param name="minimumRenderedFramesPerSecond">minimumRenderedFramesPerSecond</param>
 public void SetMinimumRenderedFramesPerSecond(SmoothStreamingMediaElement smoothStreamingMediaElement,
                                               double minimumRenderedFramesPerSecond)
 {
     if (minimumRenderedFramesPerSecond < 0.0)
     {
         throw new ArgumentOutOfRangeException("minimumRenderedFramesPerSecond");
     }
     SSMEStateInfo ssmeStateInfo =
         GetSSMEStateInfoThrowIfNotFound(smoothStreamingMediaElement);
     ssmeStateInfo.MinimumRenderedFramesPerSecond = minimumRenderedFramesPerSecond;
 }
 /// <summary>
 /// SetMinimumPlaybackBitrate
 /// </summary>
 /// <param name="smoothStreamingMediaElement">smoothStreamingMediaElement</param>
 /// <param name="minimumPlaybackBitrate">
 ///     The minimum bitrate (in bps) this SmoothStreamingMediaElement
 ///     must be capable of playing before the next SmoothStreamingMediaElement
 ///     should be enabled
 /// </param>
 public void SetMinimumPlaybackBitrate(SmoothStreamingMediaElement smoothStreamingMediaElement,
                                       ulong minimumPlaybackBitrate)
 {
     SSMEStateInfo ssmeStateInfo =
         GetSSMEStateInfoThrowIfNotFound(smoothStreamingMediaElement);
     ssmeStateInfo.MinimumPlaybackBitrate = minimumPlaybackBitrate;
 }
 /// <summary>
 /// Returns the last observed DownloadTrack.Bitrate
 /// </summary>
 /// <param name="smoothStreamingMediaElement">smoothStreamingMediaElement</param>
 public ulong GetLastDownloadBitrate(SmoothStreamingMediaElement smoothStreamingMediaElement)
 {
     SSMEStateInfo ssmeStateInfo =
         GetSSMEStateInfoThrowIfNotFound(smoothStreamingMediaElement);
     return ssmeStateInfo.LastDownloadTrackBitrate;
 }
        /// <summary>
        /// Removes a SmoothStreamingMediaElement
        /// </summary>
        /// <param name="smoothStreamingMediaElement">smoothStreamingMediaElement</param>
        public void RemoveSmoothStreamingMediaElement(SmoothStreamingMediaElement smoothStreamingMediaElement)
        {
            SSMEStateInfo ssmeStateInfo =
                GetSSMEStateInfoThrowIfNotFound(smoothStreamingMediaElement);

            UnhookEvents(ssmeStateInfo.SmoothStreamingMediaElement);
            _ssmeStateInfoList.Remove(ssmeStateInfo);
        }
 public LinearAdContext(ClipContext clipContext, SmoothStreamingMediaElement ssme)
     : base(clipContext)
 {
     if (ssme == null) throw new ArgumentNullException("ssme");
     _ssme = ssme;
 }
 /// <summary>
 /// GetSSMEStateInfoThrowIfNotFound
 /// </summary>
 /// <param name="smoothStreamingMediaElement">smoothStreamingMediaElement</param>
 private SSMEStateInfo GetSSMEStateInfoThrowIfNotFound(SmoothStreamingMediaElement smoothStreamingMediaElement)
 {
     SSMEStateInfo ssmeStateInfo = GetSSMEStateInfoBySSME(smoothStreamingMediaElement);
     if (ssmeStateInfo == null)
     {
         throw new ArgumentException(
             "smoothStreamingMediaElement is not known to this MultiSmoothStreamingMediaElementHeuristicsManager",
             "smoothStreamingMediaElement");
     }
     return ssmeStateInfo;
 }
 internal LinearAdContext(ScheduledAd scheduledAd, SmoothStreamingMediaElement ssme, object data)
     : base(scheduledAd, data)
 {
     if (ssme == null) throw new ArgumentNullException("ssme");
     _ssme = ssme;
 }
Beispiel #54
0
 private void MediaElement_ManifestMerge(SmoothStreamingMediaElement ssme)
 {
     this.SetSmoothStreamingCache();
     this.ManifestMerge.IfNotNull(i => i(this));
 }
        private void DestroySmoothStreamingMediaElement()
        {
            if (MediaElement != null)
            {
                MediaElement.ManifestReady -= MediaElement_ManifestReady;
                MediaElement.PlaybackTrackChanged -= MediaElement_PlaybackTrackChanged;
                MediaElement.MediaOpened -= MediaElement_MediaOpened;
                MediaElement.MediaFailed -= MediaElement_MediaFailed;
                MediaElement.MediaEnded -= MediaElement_MediaEnded;
                MediaElement.CurrentStateChanged -= MediaElement_CurrentStateChanged;
                MediaElement.BufferingProgressChanged -= MediaElement_BufferingProgressChanged;
                MediaElement.DownloadProgressChanged -= MediaElement_DownloadProgressChanged;
                MediaElement.LogReady -= MediaElement_LogReady;
                MediaElement.SmoothStreamingErrorOccurred -= MediaElement_SmoothStreamingErrorOccurred;
                MediaElement.SeekCompleted -= MediaElement_SeekCompleted;
                MediaElement.LiveEventCompleted -= MediaElement_LiveEventCompleted;
                MediaElement.DownloadTrackChanged -= MediaElement_DownloadTrackChanged;
#if !WINDOWS_PHONE
                MediaElement.SetPlaybackRangeCompleted -= MediaElement_SetPlaybackRangeCompleted;
                MediaElement.DrmSetupDecryptorCompleted -= MediaElement_DrmSetupDecryptorCompleted;
                MediaElement.MarkerReached -= MediaElement_MarkerReached;
                MediaElement.ClipClickThrough -= MediaElement_ClipClickThrough;
                MediaElement.ClipError -= MediaElement_ClipError;
                MediaElement.ClipProgressUpdate -= MediaElement_ClipProgressUpdate;
                MediaElement.ClipStateChanged -= MediaElement_ClipStateChanged;
                MediaElement.LinearClipChanged -= MediaElement_LinearClipChanged;
                MediaElement.ChunkDownloadFailed -= MediaElement_ChunkDownloadFailed;
#endif
                MediaElement.Dispose();
                MediaElement = null;
            }
        }
 /// <summary>
 /// Unhooks events on our referenced SSME's
 /// </summary>
 private void UnhookEvents(SmoothStreamingMediaElement ssme)
 {
     ssme.PlaybackTrackChanged -= SSME_PlaybackTrackChanged;
     ssme.DownloadTrackChanged -= SSME_DownloadTrackChanged;
 }
        public void Resume(SmoothStreamingMediaElement media)
        {
            if (media != MainMedia)
            {
                // disabling slave media
                foreach (SlaveMediaElement slave in SubMediaElements)
                {
                    if (slave.MediaElement == media)
                    {
                        slave.IsLogicalSyncEnabled = true;

                        if (slave.IsPhysicalSyncEnabled)
                        {
                            slave.MediaElement.Play();
                        }
                    }
                }
            }
            else
            {
                // disable main media
                foreach (SlaveMediaElement slave in SubMediaElements)
                {
                    slave.IsLogicalSyncEnabled = true;
                }

                MainMedia.Play();
            }
        }
        /// <summary>
        /// Attaches the SmoothStreamingMediaElement to the diagnostic component so it can be monitored.
        /// It is recommended that you do not call this directly and instead use AttachToSMF
        /// </summary>
        /// <param name="element">An instance of SSME</param>
        internal void AttachToMediaElement(SmoothStreamingMediaElement element)
        {
            // clean up the old media element just in case
            if (IsAttached)
                DetachFromMediaElement();

            // start logging agent if it hasn't been already
            if (!LoggingService.Current.IsSessionStarted)
                LoggingService.Current.StartSession();

            ssme = element;
            ssme.Unloaded += ssme_Unloaded;

            healthMonitor = new HealthMonitor(DiagConfig);
            healthMonitor.Attach(ssme);
            healthMonitorLogger.AttachMonitor(healthMonitor);

            IsAttached = true;
        }
 /// <summary>
 /// Returns the last observed RenderedFramesPerSecond
 /// </summary>
 /// <param name="smoothStreamingMediaElement">smoothStreamingMediaElement</param>
 public double GetAverageRenderedFramesPerSecond(SmoothStreamingMediaElement smoothStreamingMediaElement)
 {
     SSMEStateInfo ssmeStateInfo =
         GetSSMEStateInfoThrowIfNotFound(smoothStreamingMediaElement);
     return ssmeStateInfo.AverageRenderedFramesPerSecond;
 }
 public PlayerViewModel(SmoothStreamingMediaElement element)
 {
     this._element = element;
     this.PositionChanged += new EventHandler((object s, EventArgs e) => this.UpdatePositionInfo());
     this.BufferChanged += new EventHandler((object s, EventArgs e) => this.UpdateBufferInfo());
 }