TVSDK provides you with information so that you can act on click-through ads. As you create your player UI, you must decide how to respond when a user clicks on a clickable ad.
For TVSDK for Android, only linear ads are clickable.
When a user clicks on an ad or a related button, your application must respond. TVSDK provides you with information about the destination URL for the click.
To set up an event listener for TVSDK, and provide the click-through information, register AdClickedEventListener.onAdClicked
.
When a user clicks on an ad or a related button, TVSDK dispatches this notification, including information about the destination for the click.
Monitor user interactions on clickable ads.
When the user touches or clicks the ad or button, to notify TVSDK, call notifyClick
on the MediaPlayerView
.
Listen for the onAdClick(AdClickEvent event)
event from TVSDK.
To retrieve the click-through URL and related information, use the getter methods for the AdClickEvent
instance.
Pause the video.
For more information about pausing the video, see Pause and resume playback.
Use the click-through information to display the ad click-through URL and the related information. You can, for example, display the information in one of the following ways:
In your application, by opening the click-through URL in a browser.
On desktop platforms, the video ad playback area is used to invoke click-through URLs at user clicks.
Redirect users to their external mobile web browser.
On mobile devices, the video ad playback area is used for other functions, such as hiding and showing controls, pausing playback, expanding to full screen, and so on. On these devices, a separate view such as a sponsor button, is used to launch the click-through URL.
Close the browser window in which the click-through information is displayed and resume playing the video.
For example:
private AdStartedEventListener adStartedEventListener =
new AdStartedEventListener() {
@Override
public void onAdStarted(AdPlaybackEvent adPlaybackEvent) {
Ad ad = adPlaybackEvent.getAd();
if (ad == null) {
return;
}
_pubOverlay.startAd(adPlaybackEvent.getAdBreak(), ad);
if (areClickableAdsEnabled() && ad.isClickable()) {
_isClickableAdPlaying = true;
_playerClickableAdFragment.show();
}
}
};
private AdCompletedEventListener adCompletedEventListener =
new AdCompletedEventListener() {
@Override
public void onAdCompleted(AdPlaybackEvent adPlaybackEvent) {
Ad ad = adPlaybackEvent.getAd();
_pubOverlay.stopAd(adPlaybackEvent.getAdBreak(), ad);
_isClickableAdPlaying = false;
if (ad.isClickable()) {
_playerClickableAdFragment.hide();
}
}
};
private AdClickedEventListener adClickedEventListener =
new AdClickedEventListener() {
@Override
public void onAdClicked(AdClickEvent adClickEvent) {
AdClick adClick = adClickEvent.getAdClick();
Ad ad = adClickEvent.getAd();
String url = adClick.getUrl();
if (url == null || url.trim().equals("")) {
} else {
Uri uri = Uri.parse(url);
Intent intent = new Intent(ACTION_VIEW, uri);
try {
startActivity(intent);
} catch (Exception e) {
}
}
}
};