Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
Code cleanup
  • Loading branch information
sridhardvvce committed Nov 1, 2018
1 parent 9dead2f commit 5dce3e2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 56 deletions.
6 changes: 3 additions & 3 deletions Video.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,14 @@
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;
Expand All @@ -95,7 +96,7 @@ class ReactExoplayerView extends FrameLayout implements
}

private final VideoEventEmitter eventEmitter;

private Handler mainHandler;
private ExoPlayerView exoPlayerView;

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -164,31 +164,14 @@ public void handleMessage(Message msg) {
}
};

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);
Expand Down Expand Up @@ -263,17 +246,15 @@ public void cleanUpResources() {
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);
Expand All @@ -285,6 +266,7 @@ private void initializePlayer() {
player.setMetadataOutput(this);
exoPlayerView.setPlayer(player);
audioBecomingNoisyReceiver.setListener(this);
BANDWIDTH_METER.addEventListener(new Handler(), this);
setPlayWhenReady(!isPaused);
playerNeedsSource = true;

Expand Down Expand Up @@ -372,10 +354,10 @@ private void releasePlayer() {
player = null;
trackSelector = null;
}
bandwidthReporter.removeMessages(REPORT_BANDWIDTH);
progressHandler.removeMessages(SHOW_PROGRESS);
themedReactContext.removeLifecycleEventListener(this);
audioBecomingNoisyReceiver.removeListener();
BANDWIDTH_METER.removeEventListener(this);
}

private boolean requestAudioFocus() {
Expand Down Expand Up @@ -792,19 +774,9 @@ public void setProgressUpdateInterval(final float progressUpdateInterval) {
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) {
if (uri != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -209,14 +208,9 @@ public void setProgressUpdateInterval(final ReactExoplayerView videoView, final
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -178,7 +178,7 @@ void progressChanged(double currentPosition, double bufferedDuration, double see

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);
}

Expand Down

0 comments on commit 5dce3e2

Please sign in to comment.