Skip to content

Commit

Permalink
fix: fix disableDefaultControl for android
Browse files Browse the repository at this point in the history
  • Loading branch information
matejdr committed Feb 15, 2022
1 parent b6f8ac9 commit 448c41b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.google.ads.interactivemedia.v3.api.AdsManager;
import com.google.ads.interactivemedia.v3.api.AdsRequest;
import com.google.ads.interactivemedia.v3.api.ImaSdkFactory;
import com.google.ads.interactivemedia.v3.api.ImaSdkSettings;
import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.PlaybackParameters;
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
Expand All @@ -62,6 +63,7 @@ public class BrightcoveIMAPlayerView extends RelativeLayout implements Lifecycle
private boolean autoPlay = true;
private boolean playing = false;
private boolean adsPlaying = false;
private boolean disableDefaultControl = false;
private int bitRate = 0;
private int adVideoLoadTimeout = 3000;
private float playbackRate = 1;
Expand Down Expand Up @@ -159,6 +161,7 @@ public void processEvent(Event e) {
@Override
public void processEvent(Event e) {
mediaController.show();
mediaController.setShowHideTimeout(4000);
WritableMap event = Arguments.createMap();
ReactContext reactContext = (ReactContext) BrightcoveIMAPlayerView.this.getContext();
reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(BrightcoveIMAPlayerView.this.getId(), BrightcoveIMAPlayerViewManager.EVENT_ENTER_FULLSCREEN, event);
Expand All @@ -167,7 +170,13 @@ public void processEvent(Event e) {
eventEmitter.on(EventType.EXIT_FULL_SCREEN, new EventListener() {
@Override
public void processEvent(Event e) {
mediaController.show();
if (disableDefaultControl) {
mediaController.hide();
mediaController.setShowHideTimeout(1);
} else {
mediaController.show();
mediaController.setShowHideTimeout(4000);
}
WritableMap event = Arguments.createMap();
ReactContext reactContext = (ReactContext) BrightcoveIMAPlayerView.this.getContext();
reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(BrightcoveIMAPlayerView.this.getId(), BrightcoveIMAPlayerViewManager.EVENT_EXIT_FULLSCREEN, event);
Expand Down Expand Up @@ -197,6 +206,9 @@ public void processEvent(Event e) {

public void setSettings(ReadableMap settings) {
this.settings = settings;
if (settings != null && settings.hasKey("autoPlay")) {
this.autoPlay = settings.getBoolean("autoPlay");
}
}

public void setPolicyKey(String policyKey) {
Expand Down Expand Up @@ -227,9 +239,15 @@ public void setPlay(boolean play) {
}
}

public void setDefaultControlDisabled(boolean disabled) {
this.mediaController.hide();
this.mediaController.setShowHideTimeout(disabled ? 1 : 4000);
public void setDisableDefaultControl(boolean disabled) {
this.disableDefaultControl = disabled;
if (disabled) {
this.mediaController.hide();
this.mediaController.setShowHideTimeout(1);
} else {
this.mediaController.show();
this.mediaController.setShowHideTimeout(4000);
}
}

public void setFullscreen(boolean fullscreen) {
Expand Down Expand Up @@ -434,11 +452,18 @@ private void setupGoogleIMA() {
eventEmitter.respond(event);
});

final ImaSdkSettings imaSdkSettings = sdkFactory.createImaSdkSettings();
imaSdkSettings.setLanguage("en");
if (settings != null && settings.hasKey("publisherProvidedID")) {
imaSdkSettings.setPpid(settings.getString("publisherProvidedID"));
}

// Create the Brightcove IMA Plugin and pass in the event
// emitter so that the plugin can integrate with the SDK.
googleIMAComponent = new GoogleIMAComponent.Builder(this.brightcoveVideoView, eventEmitter)
.setUseAdRules(true)
.setLoadVideoTimeout(adVideoLoadTimeout)
.setImaSdkSettings(imaSdkSettings)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ public void setPlay(BrightcoveIMAPlayerView view, boolean play) {
}

@ReactProp(name = "disableDefaultControl")
public void setDefaultControlDisabled(BrightcoveIMAPlayerView view, boolean disableDefaultControl) {
view.setDefaultControlDisabled(disableDefaultControl);
public void setDisableDefaultControl(BrightcoveIMAPlayerView view, boolean disableDefaultControl) {
view.setDisableDefaultControl(disableDefaultControl);
}

@ReactProp(name = "volume")
Expand Down
4 changes: 2 additions & 2 deletions src/BrightcoveIMAPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ const LINKING_ERROR =

type TBrightcoveIMAPlayerSettings = {
IMAUrl: string;
autoAdvance?: boolean;
autoAdvance?: boolean; // iOS only
autoPlay?: boolean;
allowsExternalPlayback?: boolean;
allowsExternalPlayback?: boolean; // iOS only
publisherProvidedID?: string;
};

Expand Down

0 comments on commit 448c41b

Please sign in to comment.