Added channel property to allow audio panning

This commit is contained in:
Rafael Pinto 2018-06-05 02:25:46 +01:00
parent b86a2a7e12
commit 8b931cbc5d
5 changed files with 33 additions and 0 deletions

View File

@ -277,6 +277,7 @@ Video.propTypes = {
paused: PropTypes.bool, paused: PropTypes.bool,
muted: PropTypes.bool, muted: PropTypes.bool,
volume: PropTypes.number, volume: PropTypes.number,
channel: PropTypes.string,
rate: PropTypes.number, rate: PropTypes.number,
playInBackground: PropTypes.bool, playInBackground: PropTypes.bool,
playWhenInactive: PropTypes.bool, playWhenInactive: PropTypes.bool,

View File

@ -650,6 +650,12 @@ class ReactExoplayerView extends FrameLayout implements
} }
} }
public void setChannel(String channel) {
if (player != null) {
player.setChannel(channel);
}
}
public void seekTo(long positionMs) { public void seekTo(long positionMs) {
if (player != null) { if (player != null) {
eventEmitter.seek(player.getCurrentPosition(), positionMs); eventEmitter.seek(player.getCurrentPosition(), positionMs);

View File

@ -27,6 +27,7 @@ public class ReactExoplayerViewManager extends ViewGroupManager<ReactExoplayerVi
private static final String PROP_PAUSED = "paused"; private static final String PROP_PAUSED = "paused";
private static final String PROP_MUTED = "muted"; private static final String PROP_MUTED = "muted";
private static final String PROP_VOLUME = "volume"; private static final String PROP_VOLUME = "volume";
private static final String PROP_CHANNEL = "channel";
private static final String PROP_PROGRESS_UPDATE_INTERVAL = "progressUpdateInterval"; private static final String PROP_PROGRESS_UPDATE_INTERVAL = "progressUpdateInterval";
private static final String PROP_SEEK = "seek"; private static final String PROP_SEEK = "seek";
private static final String PROP_RATE = "rate"; private static final String PROP_RATE = "rate";
@ -131,6 +132,11 @@ public class ReactExoplayerViewManager extends ViewGroupManager<ReactExoplayerVi
videoView.setVolumeModifier(volume); videoView.setVolumeModifier(volume);
} }
@ReactProp(name = PROP_CHANNEL)
public void setChannel(final ReactExoplayerView videoView, final String channel) {
videoView.setChannel(channel);
}
@ReactProp(name = PROP_PROGRESS_UPDATE_INTERVAL, defaultFloat = 250.0f) @ReactProp(name = PROP_PROGRESS_UPDATE_INTERVAL, defaultFloat = 250.0f)
public void setProgressUpdateInterval(final ReactExoplayerView videoView, final float progressUpdateInterval) { public void setProgressUpdateInterval(final ReactExoplayerView videoView, final float progressUpdateInterval) {
videoView.setProgressUpdateInterval(progressUpdateInterval); videoView.setProgressUpdateInterval(progressUpdateInterval);

View File

@ -77,6 +77,10 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP
public static final String EVENT_PROP_WHAT = "what"; public static final String EVENT_PROP_WHAT = "what";
public static final String EVENT_PROP_EXTRA = "extra"; public static final String EVENT_PROP_EXTRA = "extra";
public static final String CHANNEL_LEFT = "left";
public static final String CHANNEL_BOTH = "both";
public static final String CHANNEL_RIGHT = "right";
private ThemedReactContext mThemedReactContext; private ThemedReactContext mThemedReactContext;
private RCTEventEmitter mEventEmitter; private RCTEventEmitter mEventEmitter;
@ -95,6 +99,7 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP
private boolean mPaused = false; private boolean mPaused = false;
private boolean mMuted = false; private boolean mMuted = false;
private float mVolume = 1.0f; private float mVolume = 1.0f;
private String mChannel = CHANNEL_BOTH;
private float mProgressUpdateInterval = 250.0f; private float mProgressUpdateInterval = 250.0f;
private float mRate = 1.0f; private float mRate = 1.0f;
private float mActiveRate = 1.0f; private float mActiveRate = 1.0f;
@ -368,6 +373,10 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP
if (mMuted) { if (mMuted) {
setVolume(0, 0); setVolume(0, 0);
} else if (CHANNEL_LEFT.equals(mChannel)){
setVolume(mVolume, 0);
} else if (CHANNEL_RIGHT.equals(mChannel)){
setVolume(0, mVolume);
} else { } else {
setVolume(mVolume, mVolume); setVolume(mVolume, mVolume);
} }
@ -378,6 +387,11 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP
setMutedModifier(mMuted); setMutedModifier(mMuted);
} }
public void setChannel(final String channel) {
mChannel = channel;
setMutedModifier(mMuted);
}
public void setProgressUpdateInterval(final float progressUpdateInterval) { public void setProgressUpdateInterval(final float progressUpdateInterval) {
mProgressUpdateInterval = progressUpdateInterval; mProgressUpdateInterval = progressUpdateInterval;
} }

View File

@ -30,6 +30,7 @@ public class ReactVideoViewManager extends SimpleViewManager<ReactVideoView> {
public static final String PROP_PAUSED = "paused"; public static final String PROP_PAUSED = "paused";
public static final String PROP_MUTED = "muted"; public static final String PROP_MUTED = "muted";
public static final String PROP_VOLUME = "volume"; public static final String PROP_VOLUME = "volume";
public static final String PROP_CHANNEL = "channel";
public static final String PROP_PROGRESS_UPDATE_INTERVAL = "progressUpdateInterval"; public static final String PROP_PROGRESS_UPDATE_INTERVAL = "progressUpdateInterval";
public static final String PROP_SEEK = "seek"; public static final String PROP_SEEK = "seek";
public static final String PROP_RATE = "rate"; public static final String PROP_RATE = "rate";
@ -124,6 +125,11 @@ public class ReactVideoViewManager extends SimpleViewManager<ReactVideoView> {
videoView.setVolumeModifier(volume); videoView.setVolumeModifier(volume);
} }
@ReactProp(name = PROP_CHANNEL)
public void setChannel(final ReactVideoView videoView, final String channel) {
videoView.setChannel(channel);
}
@ReactProp(name = PROP_PROGRESS_UPDATE_INTERVAL, defaultFloat = 250.0f) @ReactProp(name = PROP_PROGRESS_UPDATE_INTERVAL, defaultFloat = 250.0f)
public void setProgressUpdateInterval(final ReactVideoView videoView, final float progressUpdateInterval) { public void setProgressUpdateInterval(final ReactVideoView videoView, final float progressUpdateInterval) {
videoView.setProgressUpdateInterval(progressUpdateInterval); videoView.setProgressUpdateInterval(progressUpdateInterval);