Skip to content

Commit

Permalink
Merge branch 'release/0.2.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
chaimPaneth committed Oct 30, 2021
2 parents f3f07f9 + da5b06c commit 1d3e08f
Show file tree
Hide file tree
Showing 15 changed files with 700 additions and 234 deletions.
134 changes: 88 additions & 46 deletions README.md

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ dependencies {
implementation 'com.google.code.gson:gson:2.8.2'

// JWPlayer SDK
implementation 'com.jwplayer:jwplayer-core:4.0.0'
implementation 'com.jwplayer:jwplayer-common:4.0.0'
implementation 'com.jwplayer:jwplayer-chromecast:4.0.0'
implementation 'com.jwplayer:jwplayer-ima:4.0.0'
implementation 'com.jwplayer:jwplayer-core:4.1.0'
implementation 'com.jwplayer:jwplayer-common:4.1.0'
implementation 'com.jwplayer:jwplayer-chromecast:4.1.0'
implementation 'com.jwplayer:jwplayer-ima:4.1.0'

// Ad dependencies
implementation 'com.google.ads.interactivemedia.v3:interactivemedia:3.24.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
import com.facebook.react.uimanager.NativeViewHierarchyManager;
import com.facebook.react.uimanager.UIBlock;
import com.facebook.react.uimanager.UIManagerModule;
import com.google.android.gms.cast.CastDevice;
import com.jwplayer.pub.api.PlayerState;
import com.jwplayer.pub.api.media.audio.AudioTrack;

import java.util.List;

public class RNJWPlayerModule extends ReactContextBaseJavaModule {

Expand Down Expand Up @@ -75,6 +77,28 @@ public void execute (NativeViewHierarchyManager nvhm) {
}
}

@ReactMethod
public void togglePIP(final int reactTag) {
try {
UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
uiManager.addUIBlock(new UIBlock() {
public void execute (NativeViewHierarchyManager nvhm) {
RNJWPlayerView playerView = (RNJWPlayerView) nvhm.resolveView(reactTag);

if (playerView != null && playerView.mPlayerView != null) {
if (playerView.mPlayerView.getPlayer().isInPictureInPictureMode()) {
playerView.mPlayerView.getPlayer().exitPictureInPictureMode();
} else {
playerView.mPlayerView.getPlayer().enterPictureInPictureMode();
}
}
}
});
} catch (IllegalViewOperationException e) {
throw e;
}
}

@ReactMethod
public void setSpeed(final int reactTag, final float speed) {
try {
Expand Down Expand Up @@ -267,6 +291,76 @@ public void execute (NativeViewHierarchyManager nvhm) {
}
}

@ReactMethod
public void getAudioTracks(final int reactTag, final Promise promise) {
try {
UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
uiManager.addUIBlock(new UIBlock() {
public void execute (NativeViewHierarchyManager nvhm) {
RNJWPlayerView playerView = (RNJWPlayerView) nvhm.resolveView(reactTag);

if (playerView != null && playerView.mPlayer != null) {
List<AudioTrack> audioTrackList = playerView.mPlayer.getAudioTracks();
WritableArray audioTracks = Arguments.createArray();
for (int i = 0; i < audioTrackList.size(); i++) {
WritableMap audioTrack = Arguments.createMap();
AudioTrack track = audioTrackList.get(i);
audioTrack.putString("name", track.getName());
audioTrack.putString("language", track.getLanguage());
audioTrack.putString("groupId", track.getGroupId());
audioTrack.putBoolean("defaultTrack", track.isDefaultTrack());
audioTrack.putBoolean("autoSelect", track.isAutoSelect());
audioTracks.pushMap(audioTrack);
}
promise.resolve(audioTracks);
} else {
promise.reject("RNJW Error", "Player is null");
}
}
});
} catch (IllegalViewOperationException e) {
promise.reject("RNJW Error", e);
}
}

@ReactMethod
public void getCurrentAudioTrack(final int reactTag, final Promise promise) {
try {
UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
uiManager.addUIBlock(new UIBlock() {
public void execute (NativeViewHierarchyManager nvhm) {
RNJWPlayerView playerView = (RNJWPlayerView) nvhm.resolveView(reactTag);

if (playerView != null && playerView.mPlayer != null) {
promise.resolve(playerView.mPlayer.getCurrentAudioTrack());
} else {
promise.reject("RNJW Error", "Player is null");
}
}
});
} catch (IllegalViewOperationException e) {
promise.reject("RNJW Error", e);
}
}

@ReactMethod
public void setCurrentAudioTrack(final int reactTag, final int index) {
try {
UIManagerModule uiManager = mReactContext.getNativeModule(UIManagerModule.class);
uiManager.addUIBlock(new UIBlock() {
public void execute (NativeViewHierarchyManager nvhm) {
RNJWPlayerView playerView = (RNJWPlayerView) nvhm.resolveView(reactTag);

if (playerView != null && playerView.mPlayer != null) {
playerView.mPlayer.setCurrentAudioTrack(index);
}
}
});
} catch (IllegalViewOperationException e) {
throw e;
}
}

private int stateToInt(PlayerState playerState) {
switch (playerState) {
case IDLE:
Expand Down
Loading

0 comments on commit 1d3e08f

Please sign in to comment.