replaced channel with stereoPan attribute

This commit is contained in:
Rafael Pinto
2018-06-05 23:04:20 +01:00
parent 68dd2a72ba
commit 00fe87a2ab
6 changed files with 30 additions and 22 deletions

View File

@@ -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
@@ -77,10 +78,6 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP
public static final String EVENT_PROP_WHAT = "what";
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 RCTEventEmitter mEventEmitter;
@@ -99,7 +96,7 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP
private boolean mPaused = false;
private boolean mMuted = false;
private float mVolume = 1.0f;
private String mChannel = CHANNEL_BOTH;
private float mStereoPan = 0.0f;
private float mProgressUpdateInterval = 250.0f;
private float mRate = 1.0f;
private float mActiveRate = 1.0f;
@@ -364,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;
@@ -373,11 +378,14 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP
if (mMuted) {
setVolume(0, 0);
} else if (CHANNEL_LEFT.equals(mChannel)){
setVolume(mVolume, 0);
} else if (CHANNEL_RIGHT.equals(mChannel)){
setVolume(0, mVolume);
} 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);
}
}
@@ -387,8 +395,8 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP
setMutedModifier(mMuted);
}
public void setChannel(final String channel) {
mChannel = channel;
public void setStereoPan(final float stereoPan) {
mStereoPan = stereoPan;
setMutedModifier(mMuted);
}

View File

@@ -30,7 +30,7 @@ public class ReactVideoViewManager extends SimpleViewManager<ReactVideoView> {
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_CHANNEL = "channel";
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";
@@ -125,9 +125,9 @@ public class ReactVideoViewManager extends SimpleViewManager<ReactVideoView> {
videoView.setVolumeModifier(volume);
}
@ReactProp(name = PROP_CHANNEL)
public void setChannel(final ReactVideoView videoView, final String channel) {
videoView.setChannel(channel);
@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)