internal LinearAdContext(ScheduledAd scheduledAd, SmoothStreamingMediaElement ssme, object data)
     : base(scheduledAd, data)
 {
     if (ssme == null)
     {
         throw new ArgumentNullException("ssme");
     }
     _ssme = ssme;
 }
示例#2
0
 internal AdContext(ScheduledAd scheduledAd, object data)
 {
     if (scheduledAd == null)
     {
         throw new ArgumentNullException("scheduledAd");
     }
     _scheduledAd = scheduledAd;
     _data        = data;
 }
 internal AdContext(ScheduledAd scheduledAd, object data)
 {
     if (scheduledAd == null) throw new ArgumentNullException("scheduledAd");
     _scheduledAd = scheduledAd;
     _data = data;
 }
 internal LinearAdContext(ScheduledAd scheduledAd, SmoothStreamingMediaElement ssme, object data)
     : base(scheduledAd, data)
 {
     if (ssme == null) throw new ArgumentNullException("ssme");
     _ssme = ssme;
 }
        private void ScheduleAd(ScheduledAd scheduledAd)
        {
            if (!scheduledAd.IsScheduled)
            {
                if (scheduledAd.AppendToAd != null && !scheduledAd.AppendToAd.IsScheduled)
                {
                    ScheduleAd(scheduledAd.AppendToAd);
                }

                if (scheduledAd.StartTime.HasValue)
                {
                    if (!scheduledAd.IsLinearClip)
                    {
                        scheduledAd.ClipContext = MediaElement.ScheduleClip(scheduledAd.ClipInformation,
                                                                            scheduledAd.StartTime.Value,
                                                                            scheduledAd.PauseTimeline, scheduledAd.Data);
                    }
                    else
                    {
                        scheduledAd.ClipContext = MediaElement.ScheduleLinearClip(scheduledAd.ClipInformation,
                                                                                scheduledAd.StartTime.Value,
                                                                                scheduledAd.Data);
                    }
                }
                else if (scheduledAd.StartOffset.HasValue)
                {
                    scheduledAd.ClipContext = MediaElement.ScheduleClip(scheduledAd.ClipInformation,
                                                                        scheduledAd.PauseTimeline,
                                                                        scheduledAd.StartOffset.Value,
                                                                        scheduledAd.Data);
                }
                else if (scheduledAd.AppendToAd != null)
                {
                    scheduledAd.ClipContext = MediaElement.ScheduleClip(scheduledAd.ClipInformation,
                                                                        scheduledAd.AppendToAd.ClipContext, scheduledAd.Data);
                }
                else
                {
                    scheduledAd.ClipContext = MediaElement.ScheduleClip(scheduledAd.ClipInformation,
                                                                        scheduledAd.PauseTimeline, scheduledAd.Data);
                }
            }
        }
        /// <summary>
        /// Schedules an ad to be played by this plugin.
        /// </summary>
        /// <param name="adSource">The source of the ad content.</param>
        /// <param name="deliveryMethod">The delivery method of the ad content.</param>
        /// <param name="duration">The duration of the ad content that should be played.  If ommitted the plugin will play the full duration of the ad content.</param>
        /// <param name="startTime">The position within the media where this ad should be played.  If ommited ad will begin playing immediately.</param>
        /// <param name="clickThrough">The URL where the user should be directed when they click the ad.</param>
        /// <param name="pauseTimeline">Indicates if the timeline of the currently playing media should be paused while the ad is playing.</param>
        /// <param name="appendToAd">Another scheduled ad that this ad should be appended to.  If ommitted this ad will be scheduled independently.</param>
        /// <param name="data">User data.</param>
        /// <param name="isLinearClip">Indicates that SSME.ScheduleLinearClip should be called instead of ScheduleClip. pauseTimeline must be false.</param>
        /// <returns>A reference to the IAdContext that contains information about the scheduled ad.</returns>
        public IAdContext ScheduleAd(Uri adSource, DeliveryMethods deliveryMethod, TimeSpan? duration = null,
                                     TimeSpan? startTime = null, TimeSpan? startOffset = null, Uri clickThrough = null, bool pauseTimeline = true,
                                     IAdContext appendToAd = null, object data = null, bool isLinearClip = false)
        {
#if !WINDOWS_PHONE
            if (adSource == null) throw new ArgumentNullException("adSource");

            Duration clipDuration = duration.HasValue
                                        ? new Duration(duration.Value)
                                        : TimeSpan.MaxValue;
            var adContext = appendToAd as AdContext;
            bool isSmoothStreamingSource = deliveryMethod == DeliveryMethods.AdaptiveStreaming;
            var clipInformation = new ClipInformation(isSmoothStreamingSource, adSource, clickThrough, clipDuration);

            var scheduledAd = new ScheduledAd
                                  {
                                      IsLinearClip = isLinearClip,
                                      ClipInformation = clipInformation,
                                      StartTime = startTime,
                                      StartOffset = startOffset,
                                      PauseTimeline = pauseTimeline,
                                      Data = data,
                                      AppendToAd = appendToAd != null
                                                       ? adContext.ScheduledAd
                                                       : null
                                  };

            if (CurrentState == MediaPluginState.Closed)
            {
                //Queue the ads until ManifestReady fires
                _scheduledAds.Add(scheduledAd);
            }
            else
            {
                ScheduleAd(scheduledAd);
            }

            if (isLinearClip)
            {
                return new LinearAdContext(scheduledAd, MediaElement, data);
            }
            else
            {
                return new AdContext(scheduledAd, data);
            }
#else
            throw new NotImplementedException();
#endif
        }