diff --git a/README.md b/README.md index b1ee113e..29b876fe 100644 --- a/README.md +++ b/README.md @@ -231,6 +231,7 @@ var styles = StyleSheet.create({ * [repeat](#repeat) * [resizeMode](#resizemode) * [selectedTextTrack](#selectedtexttrack) +* [stereoPan](#stereopan) * [volume](#volume) #### ignoreSilentSwitch @@ -337,6 +338,14 @@ If a track matching the specified Type (and Value if appropriate) is unavailable Platforms: Android ExoPlayer, iOS +#### stereoPan +Adjust the balance of the left and right audio channels. Any value between –1.0 and 1.0 is accepted. +* **-1.0** - Full left +* **0.0 (default)** - Center +* **1.0** - Full right + +Platforms: Android MediaPlayer + #### volume Adjust the volume. * **1.0 (default)** - Play at full volume diff --git a/Video.js b/Video.js index 849305ea..f14e804b 100644 --- a/Video.js +++ b/Video.js @@ -284,6 +284,7 @@ Video.propTypes = { paused: PropTypes.bool, muted: PropTypes.bool, volume: PropTypes.number, + stereoPan: PropTypes.number, rate: PropTypes.number, playInBackground: PropTypes.bool, playWhenInactive: PropTypes.bool, diff --git a/android/src/main/java/com/brentvatne/react/ReactVideoView.java b/android/src/main/java/com/brentvatne/react/ReactVideoView.java index dac3d6ca..a2e0f276 100644 --- a/android/src/main/java/com/brentvatne/react/ReactVideoView.java +++ b/android/src/main/java/com/brentvatne/react/ReactVideoView.java @@ -28,6 +28,7 @@ import java.io.IOException; import java.util.HashMap; import java.util.Map; import java.lang.Math; +import java.math.BigDecimal; @SuppressLint("ViewConstructor") public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnPreparedListener, MediaPlayer @@ -95,6 +96,7 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP private boolean mPaused = false; private boolean mMuted = false; private float mVolume = 1.0f; + private float mStereoPan = 0.0f; private float mProgressUpdateInterval = 250.0f; private float mRate = 1.0f; private float mActiveRate = 1.0f; @@ -359,6 +361,14 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP } } + // reduces the volume based on stereoPan + private float calulateRelativeVolume() { + float relativeVolume = (mVolume * (1 - Math.abs(mStereoPan))); + // only one decimal allowed + BigDecimal roundRelativeVolume = new BigDecimal(relativeVolume).setScale(1, BigDecimal.ROUND_HALF_UP); + return roundRelativeVolume.floatValue(); + } + public void setMutedModifier(final boolean muted) { mMuted = muted; @@ -368,7 +378,14 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP if (mMuted) { setVolume(0, 0); + } else if (mStereoPan < 0) { + // louder on the left channel + setVolume(mVolume, calulateRelativeVolume()); + } else if (mStereoPan > 0) { + // louder on the right channel + setVolume(calulateRelativeVolume(), mVolume); } else { + // same volume on both channels setVolume(mVolume, mVolume); } } @@ -378,6 +395,11 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP setMutedModifier(mMuted); } + public void setStereoPan(final float stereoPan) { + mStereoPan = stereoPan; + setMutedModifier(mMuted); + } + public void setProgressUpdateInterval(final float progressUpdateInterval) { mProgressUpdateInterval = progressUpdateInterval; } diff --git a/android/src/main/java/com/brentvatne/react/ReactVideoViewManager.java b/android/src/main/java/com/brentvatne/react/ReactVideoViewManager.java index 983113d5..eff426a2 100644 --- a/android/src/main/java/com/brentvatne/react/ReactVideoViewManager.java +++ b/android/src/main/java/com/brentvatne/react/ReactVideoViewManager.java @@ -30,6 +30,7 @@ public class ReactVideoViewManager extends SimpleViewManager { public static final String PROP_PAUSED = "paused"; public static final String PROP_MUTED = "muted"; public static final String PROP_VOLUME = "volume"; + public static final String PROP_STEREO_PAN = "stereoPan"; public static final String PROP_PROGRESS_UPDATE_INTERVAL = "progressUpdateInterval"; public static final String PROP_SEEK = "seek"; public static final String PROP_RATE = "rate"; @@ -124,6 +125,11 @@ public class ReactVideoViewManager extends SimpleViewManager { videoView.setVolumeModifier(volume); } + @ReactProp(name = PROP_STEREO_PAN) + public void setStereoPan(final ReactVideoView videoView, final float stereoPan) { + videoView.setStereoPan(stereoPan); + } + @ReactProp(name = PROP_PROGRESS_UPDATE_INTERVAL, defaultFloat = 250.0f) public void setProgressUpdateInterval(final ReactVideoView videoView, final float progressUpdateInterval) { videoView.setProgressUpdateInterval(progressUpdateInterval);