Package com.my.target.instreamads
Class InstreamAd
- java.lang.Object
-
- com.my.target.common.BaseAd
-
- com.my.target.instreamads.InstreamAd
-
public final class InstreamAd extends BaseAd
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classInstreamAd.InstreamAdBannerModel for InStream bannerstatic classInstreamAd.InstreamAdCompanionBannerModel for companion banner.static interfaceInstreamAd.InstreamAdListener
-
Field Summary
-
Fields inherited from class com.my.target.common.BaseAd
adConfig, metricFactory
-
-
Constructor Summary
Constructors Constructor Description InstreamAd(int slotId, android.content.Context context)Public constructorInstreamAd(int slotId, MenuFactory adChoicesMenuFactory, android.content.Context context)Public constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidconfigureMidpoints(float videoDuration)Sets the duration of the main video.voidconfigureMidpoints(float videoDuration, float[] midpoints)Sets the duration of the main video.voidconfigureMidpointsPercents(float videoDuration, float[] midpointsPercents)Allows you to set the duration of the main video in seconds and an array of banner midroll points in percent.voiddestroy()Destroys the ad and frees resourcesInstreamAd.InstreamAdListenergetListener()Get events listener of an advertisementintgetLoadingTimeout()float[]getMidPoints()Method for getting a list of points at which video banners will be played.InstreamAdPlayergetPlayer()Player was set to play video ad.android.view.ViewgetShoppableView(android.content.Context context)Get the web view with shoppable ad that contains in companionintgetVideoQuality()Gets desired video quality of loading video.java.util.List<java.lang.String>getVideoSectionNames()Video section is sequence of videos based on position inside video.floatgetVolume()voidhandleAdChoicesClick(android.content.Context context)Call to display adChoicesvoidhandleClick()This should be called when user clicks on ad call-to-action element.voidhandleCompanionClick(InstreamAd.InstreamAdCompanionBanner instreamAdCompanionBanner)Opens companion's tracking link and click statistics with default app context.voidhandleCompanionClick(InstreamAd.InstreamAdCompanionBanner instreamAdCompanionBanner, android.content.Context context)Opens companion's tracking link and click statistics with contextvoidhandleCompanionShow(InstreamAd.InstreamAdCompanionBanner instreamAdCompanionBanner)Calls show/impression statistics from companion bannerbooleanisFullscreen()booleanisShoppablePresented()voidload()Start loading ads.voidpause()Pauses ad videovoidresume()Resumes ad video from pausevoidsetFullscreen(boolean fullscreen)The fullscreen property is intended to inform the InstreamAd component about changing the video playback mode to fullscreen and back.voidsetListener(InstreamAd.InstreamAdListener listener)Set events listener of an advertisement Must be called beforeload()voidsetLoadingTimeout(int loadingTimeout)An Ad loading timeout can be set before loading ad.voidsetPlayer(InstreamAdPlayer player)Sets custom implementation ofInstreamAdPlayer.voidsetShoppablePresented(boolean isPresented)The fullscreen property is intended to inform the InstreamAd component about showing shoppable ad while playing video or not.voidsetVideoQuality(int videoQuality)Desired video quality can be set.voidsetVolume(float volume)Allows you to control the volume of video playback and affects the sending of statistics of sound changes.voidshoppableAdsItemClick(java.lang.String shoppableAdsItemId)Must be called when the rendered ShoppableAdsItem has been clicked.voidshoppableAdsItemShow(java.lang.String shoppableAdsItemId)Should be called when you have rendered the ShoppableAdsItemvoidskip()Explicitly ends playing current section/sequence of ad videos.voidskipBanner()Explicitly ends playing current video banner.voidstartMidroll(float point)Starts the "midroll" section of video ad at point.voidstartPauseroll()Starts the "pauseroll" section of video advoidstartPostroll()Starts the "postroll" section of video advoidstartPreroll()Starts the "preroll" section of video advoidstop()Stops ad videovoidswapPlayer(InstreamAdPlayer player)Swaps player to another with saving it's state.voiduseDefaultPlayer()Sets the default player to play video ads.voiduseDefaultPlayer(boolean useExoPlayer)Sets the default player to play video ads.-
Methods inherited from class com.my.target.common.BaseAd
getCustomParams, isLoadCalled, setAdNetworkConfig
-
-
-
-
Constructor Detail
-
InstreamAd
public InstreamAd(int slotId, @NonNull android.content.Context context)Public constructor- Parameters:
slotId- your slot idcontext- app context
-
InstreamAd
public InstreamAd(int slotId, @NonNull MenuFactory adChoicesMenuFactory, @NonNull android.content.Context context)Public constructor- Parameters:
slotId- your slot idcontext- app contextadChoicesMenuFactory- adChoice rendering factory
-
-
Method Detail
-
getVideoSectionNames
@NonNull public java.util.List<java.lang.String> getVideoSectionNames()
Video section is sequence of videos based on position inside video. There are "preroll", "postroll", "midroll", "pauseroll". For example, if Ad has only "preroll" section name, there are some banners in preroll section, and they will start whenstartPreroll()called, and nothing will happen ifstartPostroll()called. Ad can contain one or multiple video sections to play. This method represents available sections for this ad.- Returns:
- list of available video section names
-
getListener
@Nullable public InstreamAd.InstreamAdListener getListener()
Get events listener of an advertisement- Returns:
- an instance of listener
- See Also:
InstreamAd.InstreamAdListener
-
setListener
public void setListener(@Nullable InstreamAd.InstreamAdListener listener)Set events listener of an advertisement Must be called beforeload()- See Also:
InstreamAd.InstreamAdListener
-
getLoadingTimeout
public int getLoadingTimeout()
- Returns:
- loading timeout for this Ad
- See Also:
setLoadingTimeout(int)
-
setLoadingTimeout
public void setLoadingTimeout(int loadingTimeout)
An Ad loading timeout can be set before loading ad. When timeout passes without any callbacks,InstreamAd.InstreamAdListener.onNoAd(String, InstreamAd)will be called. Default value is 10 seconds, minimum 5 seconds. If value less than 5 seconds set, it will be 5 seconds.- Parameters:
loadingTimeout- desired timeout in seconds
-
getVideoQuality
public int getVideoQuality()
Gets desired video quality of loading video. In vertical pixels.- Returns:
- video
- See Also:
setVideoQuality(int)
-
setVideoQuality
public void setVideoQuality(int videoQuality)
Desired video quality can be set. In vertical pixels. For example, if calledsetVideoQuality(360)SDK will try to show video with nearest size, so if ad has ad video with 480x800 and 1920x1080 sizes, 480x800 will be used. Default is 360- Parameters:
videoQuality- desired quality in vertical pixels
-
getPlayer
@Nullable public InstreamAdPlayer getPlayer()
Player was set to play video ad. If no player was set, method will return null- Returns:
- player for ad video playing. Null if default set
- See Also:
InstreamAdPlayer
-
setPlayer
public void setPlayer(@Nullable InstreamAdPlayer player)Sets custom implementation ofInstreamAdPlayer. Before playing, it must be set player here, or use default playeruseDefaultPlayer()- Parameters:
player- custom player implementation- See Also:
InstreamAdPlayer
-
swapPlayer
public void swapPlayer(@Nullable InstreamAdPlayer player)Swaps player to another with saving it's state. When app have multiple players, for example, main and small preview players, use this method to swich from one player to another instead ofsetPlayer(InstreamAdPlayer)- Parameters:
player- another player to smooth switch with saving state of video
-
isFullscreen
public boolean isFullscreen()
- Returns:
- param is ad in fullscreen mode or not
-
setFullscreen
public void setFullscreen(boolean fullscreen)
The fullscreen property is intended to inform the InstreamAd component about changing the video playback mode to fullscreen and back. Changing this property affects the sending of the corresponding statistics.- Parameters:
fullscreen- param is ad in fullscreen mode or not
-
isShoppablePresented
public boolean isShoppablePresented()
- Returns:
- param is shoppable ad presented or not
-
setShoppablePresented
public void setShoppablePresented(boolean isPresented)
The fullscreen property is intended to inform the InstreamAd component about showing shoppable ad while playing video or not. Changing this property affects the sending of the corresponding statistics.- Parameters:
isPresented- param is shoppable ad presented or not
-
getVolume
public float getVolume()
- Returns:
- volume param
- See Also:
setVolume(float)
-
setVolume
public void setVolume(float volume)
Allows you to control the volume of video playback and affects the sending of statistics of sound changes. When the application uses its own implementation of the player, the correct way to control the volume of the Ad is to change this property. Accepts a range of values [0-1], where 1 is max volume and 0 is mute- Parameters:
volume- volume param in range [0,1]
-
getMidPoints
@NonNull public float[] getMidPoints()
Method for getting a list of points at which video banners will be played. Should be called after calling one of theconfigureMidpoints(float), orconfigureMidpointsPercents(float, float[])methods to get an array of points based on the duration of the main video and points set by the application.- Returns:
- array of midroll points available
-
load
public void load()
Start loading ads. In case of successful loading, theInstreamAd.InstreamAdListener.onLoad(InstreamAd)method will be called on the object passed as a listener, in case of loading error or if there is no advertisement to be shown - theInstreamAd.InstreamAdListener.onNoAd(String, InstreamAd)Listener must be added before loading- See Also:
setListener(InstreamAdListener)
-
configureMidpoints
public void configureMidpoints(float videoDuration)
Sets the duration of the main video. When using this method, the points for playing the banners will be resolved automatically.- Parameters:
videoDuration- duration of the video, where should be midpoints
-
configureMidpoints
public void configureMidpoints(float videoDuration, @Nullable float[] midpoints)Sets the duration of the main video. Points will be resolved as much as possible close to the desired midpoints array- Parameters:
videoDuration- duration of the video, where should be midpointsmidpoints- an array with desired positions
-
configureMidpointsPercents
public void configureMidpointsPercents(float videoDuration, @Nullable float[] midpointsPercents)Allows you to set the duration of the main video in seconds and an array of banner midroll points in percent.- Parameters:
videoDuration- duration of the video, where should be midpointsmidpointsPercents- an array with desired positions in percents
-
useDefaultPlayer
public void useDefaultPlayer()
Sets the default player to play video ads.
-
useDefaultPlayer
public void useDefaultPlayer(boolean useExoPlayer)
Sets the default player to play video ads.- Parameters:
useExoPlayer- determines whether to use ExoPlayer or not
-
pause
public void pause()
Pauses ad video
-
resume
public void resume()
Resumes ad video from pause
-
stop
public void stop()
Stops ad video
-
skip
public void skip()
Explicitly ends playing current section/sequence of ad videos.
-
skipBanner
public void skipBanner()
Explicitly ends playing current video banner. Starts next banner then, if exists, or finishes playing video ads section
-
shoppableAdsItemShow
public void shoppableAdsItemShow(@NonNull java.lang.String shoppableAdsItemId)Should be called when you have rendered the ShoppableAdsItem- Parameters:
shoppableAdsItemId- is ShoppableAdsItem.id- See Also:
ShoppableAdsItem
-
shoppableAdsItemClick
public void shoppableAdsItemClick(@NonNull java.lang.String shoppableAdsItemId)Must be called when the rendered ShoppableAdsItem has been clicked.- Parameters:
shoppableAdsItemId- is ShopppableAdsItem.id- See Also:
ShoppableAdsItem
-
handleClick
public void handleClick()
This should be called when user clicks on ad call-to-action element. Goes to the ad placement according banner logic and calls click statistics
-
destroy
public void destroy()
Destroys the ad and frees resources
-
startPreroll
public void startPreroll()
Starts the "preroll" section of video ad
-
startPostroll
public void startPostroll()
Starts the "postroll" section of video ad
-
startPauseroll
public void startPauseroll()
Starts the "pauseroll" section of video ad
-
startMidroll
public void startMidroll(float point)
Starts the "midroll" section of video ad at point. An array of available midroll points can be getgetMidPoints()
-
handleCompanionClick
public void handleCompanionClick(@NonNull InstreamAd.InstreamAdCompanionBanner instreamAdCompanionBanner)Opens companion's tracking link and click statistics with default app context. In most cases application context will be used, so if it is needed to run with activity context, usehandleCompanionClick(InstreamAdCompanionBanner, Context)- Parameters:
instreamAdCompanionBanner- clicked companion- See Also:
InstreamAd.InstreamAdCompanionBanner
-
handleCompanionClick
public void handleCompanionClick(@NonNull InstreamAd.InstreamAdCompanionBanner instreamAdCompanionBanner, @NonNull android.content.Context context)Opens companion's tracking link and click statistics with context- Parameters:
instreamAdCompanionBanner- clicked companioncontext- context to handle intent- See Also:
InstreamAd.InstreamAdCompanionBanner
-
handleCompanionShow
public void handleCompanionShow(@NonNull InstreamAd.InstreamAdCompanionBanner instreamAdCompanionBanner)Calls show/impression statistics from companion banner- Parameters:
instreamAdCompanionBanner- showing companion- See Also:
InstreamAd.InstreamAdCompanionBanner
-
getShoppableView
@Nullable public android.view.View getShoppableView(android.content.Context context)
Get the web view with shoppable ad that contains in companion
-
handleAdChoicesClick
public void handleAdChoicesClick(@NonNull android.content.Context context)Call to display adChoices
-
-