public override void processEvent(Event @event) { Video video = (Video)@event.properties.get(Event.VIDEO); IAdContext adContext = (IAdContext)@event.properties.get(FreeWheelController.AD_CONTEXT_KEY); IConstants adConstants = adContext.Constants; // This overrides what the plugin does by default for setVideoAsset() which is to pass in currentVideo.getId(). adContext.setVideoAsset("3pqa_video", video.Duration / 1000, null, adConstants.VIDEO_ASSET_AUTO_PLAY_TYPE_ATTENDED(), (int)Math.Floor(new Random(1).NextDouble() * int.MaxValue), 0, adConstants.ID_TYPE_CUSTOM(), 0, adConstants.VIDEO_ASSET_DURATION_TYPE_EXACT()); // duration type - fallback ID - type of video ID passed (customer created or FW issued) - setting networkId for 0 as it's the default value for this method - a random number - auto play type - location - FW uses their duration as seconds; Android is in milliseconds - video ID adContext.addSiteSectionNonTemporalSlot("300x250slot", null, 300, 250, null, true, null, null); // Add preroll Log.v(outerInstance.TAG, "Adding temporal slot for prerolls"); adContext.addTemporalSlot("larry", "PREROLL", 0, null, 0, 0, null, null, 0); // Add midroll Log.v(outerInstance.TAG, "Adding temporal slot for midrolls"); int midrollCount = 1; int segmentLength = (video.Duration / 1000) / (midrollCount + 1); for (int i = 0; i < midrollCount; i++) { adContext.addTemporalSlot("moe" + i, "MIDROLL", segmentLength * (i + 1), null, 0, 0, null, null, 0); } // Add postroll Log.v(outerInstance.TAG, "Adding temporal slot for postrolls"); adContext.addTemporalSlot("curly", "POSTROLL", video.Duration / 1000, null, 0, 0, null, null, 0); // Add overlay Log.v(outerInstance.TAG, "Adding temporal slot for overlays"); adContext.addTemporalSlot("shemp", "OVERLAY", 8, null, 0, 0, null, null, 0); }
void ActiveMediaPlugin_AdProgressUpdated(IAdaptiveMediaPlugin mp, IAdContext adContext, AdProgress progress) { switch (progress) { case AdProgress.Start: startTime = DateTime.Now; OnAdVideoStart(); break; case AdProgress.FirstQuartile: OnAdVideoFirstQuartile(); break; case AdProgress.Midpoint: OnAdVideoMidpoint(); break; case AdProgress.ThirdQuartile: OnAdVideoThirdQuartile(); break; case AdProgress.Complete: OnAdVideoComplete(); break; } }
void ActiveMediaPlugin_AdStateChanged(IAdaptiveMediaPlugin arg1, IAdContext arg2) { switch (CurrentAdContext.CurrentAdState) { case MediaPluginState.Paused: case MediaPluginState.Buffering: if (!isLoaded) { OnAdLoaded(); isLoaded = true; } break; case MediaPluginState.Playing: if (!isStarted) { OnAdImpression(); OnAdStarted(); isStarted = true; } break; } }
public override void InitAd(double width, double height, string viewMode, int desiredBitrate, string creativeData, string environmentVariables) { if (ActiveMediaPlugin.SupportsAdScheduling) { // warning: we need to dispatch or app will crash if we are running this synchronously after a previous clip failed. // looks like the SSME needs time to deal with the failure. // Update: add the error to the dispatcher instead var MediaSource = new Uri(creativeData); var mimeType = AdSource.MimeType.ToLower(); var DeliveryMethod = mimeType == "video/x-ms-wmv" || mimeType == "video/mp4" ? DeliveryMethods.ProgressiveDownload : DeliveryMethods.AdaptiveStreaming; var isLive = (ActiveMediaPlugin is ILiveDvrMediaPlugin && ((ILiveDvrMediaPlugin)ActiveMediaPlugin).IsSourceLive); ActiveMediaPlugin.CurrentStateChanged += new Action <IMediaPlugin, MediaPluginState>(ActiveMediaPlugin_CurrentStateChanged); ActiveMediaPlugin.AdProgressUpdated += new Action <IAdaptiveMediaPlugin, IAdContext, AdProgress>(ActiveMediaPlugin_AdProgressUpdated); ActiveMediaPlugin.AdError += new Action <IAdaptiveMediaPlugin, IAdContext>(ActiveMediaPlugin_AdError); ActiveMediaPlugin.AdStateChanged += new Action <IAdaptiveMediaPlugin, IAdContext>(ActiveMediaPlugin_AdStateChanged); //ActiveMediaPlugin.AdClickThrough += new Action<IAdaptiveMediaPlugin, IAdContext>(ActiveMediaPlugin_AdClickThrough); CurrentAdContext = AdHost.PlayLinearAd(MediaSource, DeliveryMethod, null, null, AdSource.ClickUrl == null ? null : new Uri(AdSource.ClickUrl, UriKind.RelativeOrAbsolute), AdSource.Duration, !isLive, null, null); base.Init(width, height, viewMode, desiredBitrate, creativeData, environmentVariables); } else { OnAdError(new AdMessageEventArgs("ActiveMediaPlugin does not support ad scheduling")); } }
public override void InitAd(double width, double height, string viewMode, int desiredBitrate, string creativeData, string environmentVariables) { if (ActiveMediaPlugin.SupportsAdScheduling) { // warning: we need to dispatch or app will crash if we are running this synchronously after a previous clip failed. // looks like the SSME needs time to deal with the failure. // Update: add the error to the dispatcher instead var MediaSource = new Uri(creativeData); var mimeType = AdSource.MimeType.ToLower(); var DeliveryMethod = mimeType == "video/x-ms-wmv" || mimeType == "video/mp4" ? DeliveryMethods.ProgressiveDownload : DeliveryMethods.AdaptiveStreaming; var isLive = (ActiveMediaPlugin is ILiveDvrMediaPlugin && ((ILiveDvrMediaPlugin)ActiveMediaPlugin).IsSourceLive); ActiveMediaPlugin.CurrentStateChanged += new Action<IMediaPlugin, MediaPluginState>(ActiveMediaPlugin_CurrentStateChanged); ActiveMediaPlugin.AdProgressUpdated += new Action<IAdaptiveMediaPlugin, IAdContext, AdProgress>(ActiveMediaPlugin_AdProgressUpdated); ActiveMediaPlugin.AdError += new Action<IAdaptiveMediaPlugin, IAdContext>(ActiveMediaPlugin_AdError); ActiveMediaPlugin.AdStateChanged += new Action<IAdaptiveMediaPlugin, IAdContext>(ActiveMediaPlugin_AdStateChanged); //ActiveMediaPlugin.AdClickThrough += new Action<IAdaptiveMediaPlugin, IAdContext>(ActiveMediaPlugin_AdClickThrough); CurrentAdContext = AdHost.PlayLinearAd(MediaSource, DeliveryMethod, null, null, AdSource.ClickUrl == null ? null : new Uri(AdSource.ClickUrl, UriKind.RelativeOrAbsolute), AdSource.Duration, !isLive, null, null); base.Init(width, height, viewMode, desiredBitrate, creativeData, environmentVariables); } else { OnAdError(new AdMessageEventArgs("ActiveMediaPlugin does not support ad scheduling")); } }
public AdvertisementRepo(IAdContext db) { _db = db; }
/// <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> /// <returns>A reference to the IAdContext that contains information about the scheduled ad.</returns> public IAdContext ScheduleAdvertisement(Uri adSource, DeliveryMethods deliveryMethod, TimeSpan? startTime, TimeSpan? startOffset, Uri clickThrough = null, TimeSpan? duration = null, bool pauseTimeline = true, IAdContext appendToAd = null, object data = null, bool isLinearClip = false) { IAdContext adContext = null; if (ActiveMediaPlugin != null && ActiveMediaPlugin.SupportsAdScheduling) { if (deliveryMethod == DeliveryMethods.NotSpecified || (ActiveMediaPlugin.SupportedDeliveryMethods & deliveryMethod) != DeliveryMethods.NotSpecified) { adContext = ActiveMediaPlugin.ScheduleAd(adSource, deliveryMethod, duration, startTime, startOffset, clickThrough, pauseTimeline, appendToAd, data, isLinearClip); } else { string message = string.Format(SilverlightMediaFrameworkResources.UnsupportedAdDeliveryMethodExceptionMessage, deliveryMethod); SendLogEntry(KnownLogEntryTypes.ScheduleAdvertisement, LogLevel.Warning, message); throw new ArgumentException(message, "deliveryMethod"); } } return adContext; }
private void MediaPlugin_AdError(IAdaptiveMediaPlugin mediaPlugin, IAdContext adContext) { AdError(adContext); AdvertisementError.IfNotNull(i => i(this, new CustomEventArgs<IAdContext>(adContext))); }
private void LoadClip(double width, double height, string viewMode, int desiredBitrate, string creativeData, string environmentVariables, IAdContext AppendToAdContext) { if (ActiveMediaPlugin.SupportsAdScheduling) { // warning: we need to dispatch or app will crash if we are running this synchronously after a previous clip failed. // looks like the SSME needs time to deal with the failure. // Update: add the error to the dispatcher instead var MediaSource = new Uri(creativeData); var mimeType = AdSource.MimeType.ToLower(); var DeliveryMethod = mimeType == "video/x-ms-wmv" || mimeType == "video/mp4" ? DeliveryMethods.ProgressiveDownload : DeliveryMethods.AdaptiveStreaming; var isLive = (ActiveMediaPlugin is ILiveDvrMediaPlugin && ((ILiveDvrMediaPlugin)ActiveMediaPlugin).IsSourceLive); // If the user has included a true EnforceAdDuration flag, pad the specified duration to allow for a slight variation in // ad length and pass that value to the player - the player will end the ad at the duration (regardless of actual ad length). // If the flag is not included or it is false, pass a null duration to the player to let it play the ad in its entirety. bool enforceAdDuration = GetEnforceAdDuration(AdHost); TimeSpan? adDuration = null; double durationPadding = 1.0; // seconds if (enforceAdDuration && AdSource.Duration != null && AdSource.Duration.Value.TotalSeconds > durationPadding) { adDuration = AdSource.Duration.Value.Add(TimeSpan.FromSeconds(durationPadding)); } Uri clickUri = AdSource.ClickUrl == null ? null : new Uri(AdSource.ClickUrl, UriKind.RelativeOrAbsolute); currentAdContext = AdHost.PlayLinearAd(MediaSource, DeliveryMethod, null, null, clickUri, adDuration, !isLive, AppendToAdContext, this); base.Init(width, height, viewMode, desiredBitrate, creativeData, environmentVariables); } else { OnAdError(new AdMessageEventArgs("ActiveMediaPlugin does not support ad scheduling")); } }
void ActiveMediaPlugin_AdClickThrough(IAdaptiveMediaPlugin mediaPlugin, IAdContext adContext) { if (adContext != null && adContext.Data != this) return; OnAdClickThru(new AdClickThruEventArgs(adContext.ClickThrough.OriginalString, AdSource.Id, true)); }
void ActiveMediaPlugin_AdProgressUpdated(IAdaptiveMediaPlugin mp, IAdContext adContext, AdProgress progress) { switch (progress) { case AdProgress.Start: startTime = DateTime.Now; OnAdVideoStart(); break; case AdProgress.FirstQuartile: OnAdVideoFirstQuartile(); break; case AdProgress.Midpoint: OnAdVideoMidpoint(); break; case AdProgress.ThirdQuartile: OnAdVideoThirdQuartile(); break; case AdProgress.Complete: OnAdVideoComplete(); break; } }
partial void AdProgressUpdated(IAdContext adContext, AdProgress adProgress);
partial void AdStateChanged(IAdContext adContext);
/// <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 }
void ActiveMediaPlugin_AdError(IAdaptiveMediaPlugin mp, IAdContext adContext) { if (adContext != null && adContext.Data != this) return; OnAdError(new AdMessageEventArgs("An unknown error occured while playing the ad clip.")); }
public AdService(IAdContext context) { _context = context ?? throw new NullReferenceException(nameof(context)); }
/// <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> /// <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) { throw new NotImplementedException(); }
public IAdContext ScheduleAd(Uri adSource, DeliveryMethods deliveryMethod, TimeSpan?duration, TimeSpan?startTime, TimeSpan?startOffset, Uri clickThrough, bool pauseTimeline, IAdContext appendToAd, object data) { throw new NotImplementedException(); }
void ActiveMediaPlugin_AdError(IAdaptiveMediaPlugin mp, IAdContext adContext) { OnAdError(new AdMessageEventArgs("An unknown error occured while playing the ad clip.")); }
partial void AdError(IAdContext adContext);
void ActiveMediaPlugin_AdStateChanged(IAdaptiveMediaPlugin arg1, IAdContext arg2) { switch (CurrentAdContext.CurrentAdState) { case MediaPluginState.Paused: case MediaPluginState.Buffering: if (!isLoaded) { OnAdLoaded(); isLoaded = true; } break; case MediaPluginState.Playing: if (!isStarted) { OnAdImpression(); OnAdStarted(); isStarted = true; } break; } }
void ActiveMediaPlugin_AdClickThrough(IAdaptiveMediaPlugin mediaPlugin, IAdContext adContext) { OnAdClickThru(new AdClickThruEventArgs(adContext.ClickThrough.OriginalString, AdSource.Id, true)); }
void ActiveMediaPlugin_AdClickThrough(IAdaptiveMediaPlugin mediaPlugin, IAdContext adContext) { OnAdClickThru(new AdClickThruEventArgs(adContext.ClickThrough.OriginalString, AdSource.Id, true)); }
IAdContext IPlayer.PlayLinearAd(Uri adSource, DeliveryMethods deliveryMethod, TimeSpan? startTime, TimeSpan? startOffset, Uri clickThrough, TimeSpan? duration, bool pauseTimeline, IAdContext appendToAd, object data) { return this.ScheduleAdvertisement(adSource, deliveryMethod, startTime, startOffset, clickThrough, duration, pauseTimeline, appendToAd, data); }
void ActiveMediaPlugin_AdError(IAdaptiveMediaPlugin mp, IAdContext adContext) { OnAdError(new AdMessageEventArgs("An unknown error occured while playing the ad clip.")); }
public override void Dispose() { if (ActiveMediaPlugin != null) { //ActiveMediaPlugin.AdClickThrough -= new Action<IAdaptiveMediaPlugin, IAdContext>(ActiveMediaPlugin_AdClickThrough); ActiveMediaPlugin.AdProgressUpdated -= new Action<IAdaptiveMediaPlugin, IAdContext, AdProgress>(ActiveMediaPlugin_AdProgressUpdated); //ActiveMediaPlugin.AdError -= new Action<IAdaptiveMediaPlugin, IAdContext>(ActiveMediaPlugin_AdError); ((Microsoft.SilverlightMediaFramework.Core.SMFPlayer)AdHost).AdvertisementError -= AdClipLinearAdPlayer_AdvertisementError; //ActiveMediaPlugin.AdStateChanged -= new Action<IAdaptiveMediaPlugin, IAdContext>(ActiveMediaPlugin_AdStateChanged); ((Microsoft.SilverlightMediaFramework.Core.SMFPlayer)AdHost).AdvertisementStateChanged -= AdClipLinearAdPlayer_AdvertisementStateChanged; } currentAdContext = null; base.Dispose(); }
private void MediaPlugin_AdProgressUpdated(IAdaptiveMediaPlugin mediaPlugin, IAdContext adContext, AdProgress adProgress) { SendLogEntry(KnownLogEntryTypes.AdProgressUpdated, extendedProperties: new Dictionary<string, object> { { "Progress", adProgress.ToString() } }); AdProgressUpdated(adContext, adProgress); AdvertisementProgressChanged.IfNotNull(i => i(this, new AdvertisementProgressChangedInfo { AdContext = adContext, AdProgress = adProgress })); }
void ActiveMediaPlugin_AdStateChanged(IAdaptiveMediaPlugin mp, IAdContext adContext) { if (adContext != null && adContext.Data != this) return; switch (currentAdContext.CurrentAdState) { case MediaPluginState.Paused: case MediaPluginState.Buffering: if (!isLoaded) { OnAdLoaded(); isLoaded = true; } break; case MediaPluginState.Playing: if (!isStarted) { OnAdImpression(); OnAdStarted(); isStarted = true; } break; } }
private void mediaPlugin_AdStateChanged(IAdaptiveMediaPlugin mediaPlugin, IAdContext adContext) { SendLogEntry(KnownLogEntryTypes.AdProgressUpdated, extendedProperties: new Dictionary<string, object> { { "State", adContext.CurrentAdState.ToString() } }); AdStateChanged(adContext); AdvertisementStateChanged.IfNotNull(i => i(this, new AdvertisementStateChangedInfo { AdContext = adContext })); }
private void MediaPlugin_AdClickThrough(IAdaptiveMediaPlugin mediaPlugin, IAdContext adContext) { SendLogEntry(KnownLogEntryTypes.AdClickThrough); AdvertisementClickThrough.IfNotNull(i => i(this, new CustomEventArgs<IAdContext>(adContext))); }
IAdContext IPlayer.PlayLinearAd(Uri adSource, DeliveryMethods deliveryMethod, TimeSpan?startTime, TimeSpan?startOffset, Uri clickThrough, TimeSpan?duration, bool pauseTimeline, IAdContext appendToAd, object data) { return(this.ScheduleAdvertisement(adSource, deliveryMethod, startTime, startOffset, clickThrough, duration, pauseTimeline, appendToAd, 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> /// <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) { throw new NotImplementedException(); }