replaced channel with stereoPan attribute
This commit is contained in:
parent
68dd2a72ba
commit
00fe87a2ab
@ -188,7 +188,7 @@ using System.Collections.Generic;
|
||||
}} // Store reference
|
||||
rate={1.0} // 0 is paused, 1 is normal.
|
||||
volume={1.0} // 0 is muted, 1 is normal.
|
||||
channel="both" // [Android only] Target channel for audio panning: left, right or both (default).
|
||||
stereoPan={0} // [Android only] The audio player’s stereo pan position. A value of –1.0 is full left, 0.0 is center, and 1.0 is full right. Default 0.0
|
||||
muted={true|false} // Mutes the audio entirely. Default false
|
||||
paused={true|false} // Pauses playback entirely. Default false
|
||||
resizeMode="cover" // Fill the whole screen at aspect ratio.*
|
||||
|
2
Video.js
2
Video.js
@ -277,7 +277,7 @@ Video.propTypes = {
|
||||
paused: PropTypes.bool,
|
||||
muted: PropTypes.bool,
|
||||
volume: PropTypes.number,
|
||||
channel: PropTypes.string,
|
||||
stereoPan: PropTypes.number,
|
||||
rate: PropTypes.number,
|
||||
playInBackground: PropTypes.bool,
|
||||
playWhenInactive: PropTypes.bool,
|
||||
|
@ -650,9 +650,9 @@ class ReactExoplayerView extends FrameLayout implements
|
||||
}
|
||||
}
|
||||
|
||||
public void setChannel(String channel) {
|
||||
public void setStereoPan(float stereoPan) {
|
||||
if (player != null) {
|
||||
player.setChannel(channel);
|
||||
player.setStereoPan(stereoPan);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -132,9 +132,9 @@ public class ReactExoplayerViewManager extends ViewGroupManager<ReactExoplayerVi
|
||||
videoView.setVolumeModifier(volume);
|
||||
}
|
||||
|
||||
@ReactProp(name = PROP_CHANNEL)
|
||||
public void setChannel(final ReactExoplayerView videoView, final String channel) {
|
||||
videoView.setChannel(channel);
|
||||
@ReactProp(name = PROP_STEREO_PAN)
|
||||
public void setStereoPan(final ReactExoplayerView videoView, final float stereoPan) {
|
||||
videoView.setStereoPan(stereoPan);
|
||||
}
|
||||
|
||||
@ReactProp(name = PROP_PROGRESS_UPDATE_INTERVAL, defaultFloat = 250.0f)
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user