mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Allow apps to handle ad clicked/tapped events
Issue: #3106 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=163455563
This commit is contained in:
parent
8e7a52483a
commit
ad5c8af019
@ -61,7 +61,7 @@ public final class ImaAdsLoader implements Player.EventListener, VideoAdPlayer,
|
||||
/**
|
||||
* Listener for ad loader events. All methods are called on the main thread.
|
||||
*/
|
||||
public interface EventListener {
|
||||
/* package */ interface EventListener {
|
||||
|
||||
/**
|
||||
* Called when the ad playback state has been updated.
|
||||
@ -77,6 +77,16 @@ public final class ImaAdsLoader implements Player.EventListener, VideoAdPlayer,
|
||||
*/
|
||||
void onLoadError(IOException error);
|
||||
|
||||
/**
|
||||
* Called when the user clicks through an ad (for example, following a 'learn more' link).
|
||||
*/
|
||||
void onAdClicked();
|
||||
|
||||
/**
|
||||
* Called when the user taps a non-clickthrough part of an ad.
|
||||
*/
|
||||
void onAdTapped();
|
||||
|
||||
}
|
||||
|
||||
static {
|
||||
@ -337,6 +347,16 @@ public final class ImaAdsLoader implements Player.EventListener, VideoAdPlayer,
|
||||
imaPausedContent = true;
|
||||
pauseContentInternal();
|
||||
break;
|
||||
case TAPPED:
|
||||
if (eventListener != null) {
|
||||
eventListener.onAdTapped();
|
||||
}
|
||||
break;
|
||||
case CLICKED:
|
||||
if (eventListener != null) {
|
||||
eventListener.onAdClicked();
|
||||
}
|
||||
break;
|
||||
case CONTENT_RESUME_REQUESTED:
|
||||
imaPausedContent = false;
|
||||
resumeContentInternal();
|
||||
|
@ -53,6 +53,16 @@ public final class ImaAdsMediaSource implements MediaSource {
|
||||
*/
|
||||
void onAdLoadError(IOException error);
|
||||
|
||||
/**
|
||||
* Called when the user clicks through an ad (for example, following a 'learn more' link).
|
||||
*/
|
||||
void onAdClicked();
|
||||
|
||||
/**
|
||||
* Called when the user taps a non-clickthrough part of an ad.
|
||||
*/
|
||||
void onAdTapped();
|
||||
|
||||
}
|
||||
|
||||
private static final String TAG = "ImaAdsMediaSource";
|
||||
@ -305,6 +315,34 @@ public final class ImaAdsMediaSource implements MediaSource {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAdClicked() {
|
||||
if (eventHandler != null && eventListener != null) {
|
||||
eventHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!released) {
|
||||
eventListener.onAdClicked();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAdTapped() {
|
||||
if (eventHandler != null && eventListener != null) {
|
||||
eventHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!released) {
|
||||
eventListener.onAdTapped();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user