implemented ad event propogation towards react component from native view for android.
This commit is contained in:
parent
7e9e9e1393
commit
79b659d614
@ -45,3 +45,33 @@ dependencies {
|
||||
implementation 'com.squareup.okhttp3:okhttp:${OKHTTP_VERSION}'
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* If one wants to open this module in Android studio. Uncomment these repositories and buildscript parts*/
|
||||
|
||||
/*
|
||||
repositories {
|
||||
maven {
|
||||
url 'https://maven.google.com/'
|
||||
name 'Google'
|
||||
}
|
||||
jcenter()
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
maven {
|
||||
url 'https://maven.google.com/'
|
||||
name 'Google'
|
||||
}
|
||||
jcenter()
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.5.3'
|
||||
}
|
||||
}
|
||||
*/
|
@ -26,6 +26,7 @@ import com.facebook.react.bridge.ReadableMap;
|
||||
import com.facebook.react.bridge.WritableArray;
|
||||
import com.facebook.react.bridge.WritableMap;
|
||||
import com.facebook.react.uimanager.ThemedReactContext;
|
||||
import com.google.ads.interactivemedia.v3.api.AdEvent;
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.DefaultLoadControl;
|
||||
import com.google.android.exoplayer2.DefaultRenderersFactory;
|
||||
@ -92,7 +93,7 @@ class ReactExoplayerView extends FrameLayout implements
|
||||
BecomingNoisyListener,
|
||||
AudioManager.OnAudioFocusChangeListener,
|
||||
MetadataOutput,
|
||||
DefaultDrmSessionEventListener {
|
||||
DefaultDrmSessionEventListener, AdEvent.AdEventListener {
|
||||
|
||||
private static final String TAG = "ReactExoplayerView";
|
||||
|
||||
@ -1049,6 +1050,8 @@ class ReactExoplayerView extends FrameLayout implements
|
||||
public void setAdTagUrl(final Uri uri) {
|
||||
adTagUrl = uri;
|
||||
adsLoader = new ImaAdsLoader(this.themedReactContext, adTagUrl);
|
||||
adsLoader = new ImaAdsLoader.Builder(this.themedReactContext).setAdEventListener(this).buildForAdTag(adTagUrl);
|
||||
|
||||
}
|
||||
|
||||
public void setRawSrc(final Uri uri, final String extension) {
|
||||
@ -1399,4 +1402,10 @@ class ReactExoplayerView extends FrameLayout implements
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAdEvent(AdEvent adEvent) {
|
||||
eventEmitter.receiveAdEvent(adEvent.getType().name());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -47,6 +47,7 @@ class VideoEventEmitter {
|
||||
private static final String EVENT_AUDIO_BECOMING_NOISY = "onVideoAudioBecomingNoisy";
|
||||
private static final String EVENT_AUDIO_FOCUS_CHANGE = "onAudioFocusChanged";
|
||||
private static final String EVENT_PLAYBACK_RATE_CHANGE = "onPlaybackRateChange";
|
||||
private static final String EVENT_ON_RECEIVE_AD_EVENT = "onReceiveAdEvent";
|
||||
|
||||
static final String[] Events = {
|
||||
EVENT_LOAD_START,
|
||||
@ -69,6 +70,7 @@ class VideoEventEmitter {
|
||||
EVENT_AUDIO_FOCUS_CHANGE,
|
||||
EVENT_PLAYBACK_RATE_CHANGE,
|
||||
EVENT_BANDWIDTH,
|
||||
EVENT_ON_RECEIVE_AD_EVENT
|
||||
};
|
||||
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@ -93,6 +95,7 @@ class VideoEventEmitter {
|
||||
EVENT_AUDIO_FOCUS_CHANGE,
|
||||
EVENT_PLAYBACK_RATE_CHANGE,
|
||||
EVENT_BANDWIDTH,
|
||||
EVENT_ON_RECEIVE_AD_EVENT
|
||||
})
|
||||
@interface VideoEvents {
|
||||
}
|
||||
@ -298,6 +301,13 @@ class VideoEventEmitter {
|
||||
receiveEvent(EVENT_AUDIO_BECOMING_NOISY, null);
|
||||
}
|
||||
|
||||
void receiveAdEvent(String event) {
|
||||
WritableMap map = Arguments.createMap();
|
||||
map.putString("event", event);
|
||||
|
||||
receiveEvent(EVENT_ON_RECEIVE_AD_EVENT, map);
|
||||
}
|
||||
|
||||
private void receiveEvent(@VideoEvents String type, WritableMap event) {
|
||||
eventEmitter.receiveEvent(viewId, type, event);
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-native-video-inc-ads",
|
||||
"version": "0.0.2",
|
||||
"version": "0.0.3",
|
||||
"description": "A <Video /> element for react-native with ads support. This is a project merging a fork and its master",
|
||||
"main": "Video.js",
|
||||
"license": "MIT",
|
||||
|
Loading…
Reference in New Issue
Block a user