void MediaPlayer_MediaOpened(object sender, RoutedEventArgs e)
        {
            HandledAds.Clear();
            InitializeAdvertisements();

            OnMediaOpened();

            if (PreloadTime.HasValue)
            {
                // schedule the first postroll for preloading (x seconds before the duration)
                var postroll = Advertisements.FirstOrDefault(a => a is PostrollAdvertisement);
                if (postroll != null)
                {
                    MediaPlayer.Markers.Add(new TimelineMarker()
                    {
                        Type = MarkerType_Preload, Text = postroll.Id, Time = TimeSpanExtensions.Max(TimeSpan.FromMilliseconds(1), MediaPlayer.Duration.Subtract(PreloadTime.Value))
                    });                                                                                                                                                                                                             // clamp to 1 ms
                }
            }
        }
 void MediaPlayer_MediaClosed(object sender, RoutedEventArgs e)
 {
     Advertisements.Clear();
     HandledAds.Clear();
 }