Code cleanup

Code cleanup
This commit is contained in:
sridhar 2018-11-01 21:41:57 +05:30
parent 9dead2fefc
commit 5dce3e2161
4 changed files with 22 additions and 56 deletions

View File

@ -246,7 +246,7 @@ export default class Video extends Component {
onVideoSeek: this._onSeek,
onVideoEnd: this._onEnd,
onVideoBuffer: this._onBuffer,
onBandwidthUpdate: this._onBandwidthUpdate,
onVideoBandwidthUpdate: this._onBandwidthUpdate,
onTimedMetadata: this._onTimedMetadata,
onVideoAudioBecomingNoisy: this._onAudioBecomingNoisy,
onVideoExternalPlaybackChange: this._onExternalPlaybackChange,
@ -294,7 +294,7 @@ Video.propTypes = {
onVideoBuffer: PropTypes.func,
onVideoError: PropTypes.func,
onVideoProgress: PropTypes.func,
onBandwidthUpdate: PropTypes.func,
onVideoBandwidthUpdate: PropTypes.func,
onVideoSeek: PropTypes.func,
onVideoEnd: PropTypes.func,
onTimedMetadata: PropTypes.func,
@ -366,7 +366,6 @@ Video.propTypes = {
playWhenInactive: PropTypes.bool,
ignoreSilentSwitch: PropTypes.oneOf(['ignore', 'obey']),
reportBandwidth: PropTypes.bool,
bandwidthUpdateInterval: PropTypes.number,
disableFocus: PropTypes.bool,
controls: PropTypes.bool,
audioOnly: PropTypes.bool,
@ -379,6 +378,7 @@ Video.propTypes = {
onBuffer: PropTypes.func,
onError: PropTypes.func,
onProgress: PropTypes.func,
onBandwidthUpdate: PropTypes.func,
onSeek: PropTypes.func,
onEnd: PropTypes.func,
onFullscreenPlayerWillPresent: PropTypes.func,

View File

@ -78,13 +78,14 @@ import java.util.Locale;
class ReactExoplayerView extends FrameLayout implements
LifecycleEventListener,
ExoPlayer.EventListener,
BandwidthMeter.EventListener,
BecomingNoisyListener,
AudioManager.OnAudioFocusChangeListener,
MetadataRenderer.Output {
private static final String TAG = "ReactExoplayerView";
private static DefaultBandwidthMeter BANDWIDTH_METER;
private static final DefaultBandwidthMeter BANDWIDTH_METER = new DefaultBandwidthMeter();
private static final CookieManager DEFAULT_COOKIE_MANAGER;
private static final int SHOW_PROGRESS = 1;
private static final int REPORT_BANDWIDTH = 1;
@ -135,7 +136,6 @@ class ReactExoplayerView extends FrameLayout implements
private boolean playInBackground = false;
private boolean useTextureView = false;
private Map<String, String> requestHeaders;
private float mBandwidthUpdateInterval = 250.0f;
private boolean mReportBandwidth = false;
// \ End props
@ -164,31 +164,14 @@ class ReactExoplayerView extends FrameLayout implements
}
};
private final Handler bandwidthReporter = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case REPORT_BANDWIDTH:
if (player != null) {
long bitRateEstimate = BANDWIDTH_METER.getBitrateEstimate();
eventEmitter.bandwidthReport(bitRateEstimate);
msg = obtainMessage(REPORT_BANDWIDTH);
sendMessageDelayed(msg, Math.round(mBandwidthUpdateInterval));
}
break;
}
}
};
public ReactExoplayerView(ThemedReactContext context) {
super(context);
this.themedReactContext = context;
buildBandwidthMeter();
this.eventEmitter = new VideoEventEmitter(context);
createViews();
this.eventEmitter = new VideoEventEmitter(context);
audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
themedReactContext.addLifecycleEventListener(this);
audioBecomingNoisyReceiver = new AudioBecomingNoisyReceiver(themedReactContext);
@ -263,17 +246,15 @@ class ReactExoplayerView extends FrameLayout implements
stopPlayback();
}
// Internal methods
private void buildBandwidthMeter() {
BANDWIDTH_METER = new DefaultBandwidthMeter(new Handler(), new BandwidthMeter.EventListener() {
@Override
public void onBandwidthSample(int elapsedMs, long bytes, long bitrate) {
System.out.println("Debug::::In function onBandwidthSample, elapsedMs = " + elapsedMs + " bytes = " + bytes + " bitrate = " + bitrate);
}
});
//BandwidthMeter.EventListener implementation
@Override
public void onBandwidthSample(int elapsedMs, long bytes, long bitrate) {
if (mReportBandwidth == true) {
eventEmitter.bandwidthReport(bitrate);
}
}
// Internal methods
private void initializePlayer() {
if (player == null) {
TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER);
@ -285,6 +266,7 @@ class ReactExoplayerView extends FrameLayout implements
player.setMetadataOutput(this);
exoPlayerView.setPlayer(player);
audioBecomingNoisyReceiver.setListener(this);
BANDWIDTH_METER.addEventListener(new Handler(), this);
setPlayWhenReady(!isPaused);
playerNeedsSource = true;
@ -372,10 +354,10 @@ class ReactExoplayerView extends FrameLayout implements
player = null;
trackSelector = null;
}
bandwidthReporter.removeMessages(REPORT_BANDWIDTH);
progressHandler.removeMessages(SHOW_PROGRESS);
themedReactContext.removeLifecycleEventListener(this);
audioBecomingNoisyReceiver.removeListener();
BANDWIDTH_METER.removeEventListener(this);
}
private boolean requestAudioFocus() {
@ -792,18 +774,8 @@ class ReactExoplayerView extends FrameLayout implements
mProgressUpdateInterval = progressUpdateInterval;
}
public void setBandwidthUpdateInterval(final float bandwidthUpdateInterval) {
mBandwidthUpdateInterval = bandwidthUpdateInterval;
}
public void setReportBandwidthModifier(boolean reportBandwidth) {
public void setReportBandwidth(boolean reportBandwidth) {
mReportBandwidth = reportBandwidth;
if (mReportBandwidth) {
bandwidthReporter.removeMessages(REPORT_BANDWIDTH);
bandwidthReporter.sendEmptyMessage(REPORT_BANDWIDTH);
} else {
bandwidthReporter.removeMessages(REPORT_BANDWIDTH);
}
}
public void setRawSrc(final Uri uri, final String extension) {

View File

@ -45,7 +45,6 @@ public class ReactExoplayerViewManager extends ViewGroupManager<ReactExoplayerVi
private static final String PROP_BUFFER_CONFIG_BUFFER_FOR_PLAYBACK_MS = "bufferForPlaybackMs";
private static final String PROP_BUFFER_CONFIG_BUFFER_FOR_PLAYBACK_AFTER_REBUFFER_MS = "bufferForPlaybackAfterRebufferMs";
private static final String PROP_PROGRESS_UPDATE_INTERVAL = "progressUpdateInterval";
private static final String PROP_BANDWIDTH_UPDATE_INTERVAL = "bandwidthUpdateInterval";
private static final String PROP_REPORT_BANDWIDTH = "reportBandwidth";
private static final String PROP_SEEK = "seek";
private static final String PROP_RATE = "rate";
@ -209,14 +208,9 @@ public class ReactExoplayerViewManager extends ViewGroupManager<ReactExoplayerVi
videoView.setProgressUpdateInterval(progressUpdateInterval);
}
@ReactProp(name = PROP_BANDWIDTH_UPDATE_INTERVAL, defaultFloat = 250.0f)
public void setBandwidthUpdateInterval(final ReactExoplayerView videoView, final float bandwidthUpdateInterval) {
videoView.setBandwidthUpdateInterval(bandwidthUpdateInterval);
}
@ReactProp(name = PROP_REPORT_BANDWIDTH, defaultBoolean = false)
public void setReportBandwidth(final ReactExoplayerView videoView, final boolean reportBandwidth) {
videoView.setReportBandwidthModifier(reportBandwidth);
videoView.setReportBandwidth(reportBandwidth);
}
@ReactProp(name = PROP_SEEK)

View File

@ -29,7 +29,7 @@ class VideoEventEmitter {
private static final String EVENT_LOAD = "onVideoLoad";
private static final String EVENT_ERROR = "onVideoError";
private static final String EVENT_PROGRESS = "onVideoProgress";
private static final String EVENT_BANDWIDTH = "onBandwidthUpdate";
private static final String EVENT_BANDWIDTH = "onVideoBandwidthUpdate";
private static final String EVENT_SEEK = "onVideoSeek";
private static final String EVENT_END = "onVideoEnd";
private static final String EVENT_FULLSCREEN_WILL_PRESENT = "onVideoFullscreenPlayerWillPresent";
@ -178,7 +178,7 @@ class VideoEventEmitter {
void bandwidthReport(double bitRateEstimate) {
WritableMap event = Arguments.createMap();
event.putDouble(EVENT_PROP_BITRATE_ESTIMATE, bitRateEstimate / 1000D);
event.putDouble(EVENT_PROP_BITRATE_ESTIMATE, bitRateEstimate / 1024D);
receiveEvent(EVENT_BANDWIDTH, event);
}