From 4ea926e1375b14bf577b77d09a2da0d968799b66 Mon Sep 17 00:00:00 2001 From: sridhar Date: Sat, 25 Aug 2018 11:21:01 +0530 Subject: [PATCH] Bandwidth reporting To show the current bandwidth to user and for debugging purposes current bandwidth is required to be reported. This pull request adds the bandwidth estimate in the progress event. Also the bandwidth details are added in the audio track in load event. There is another pull request which reports the video track information --- .../java/com/brentvatne/exoplayer/ReactExoplayerView.java | 5 ++++- .../java/com/brentvatne/exoplayer/VideoEventEmitter.java | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java index bcac252f..eb303e14 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java @@ -149,9 +149,10 @@ class ReactExoplayerView extends FrameLayout implements && player.getPlaybackState() == ExoPlayer.STATE_READY && player.getPlayWhenReady() ) { + long bitRateEstimate = BANDWIDTH_METER.getBitrateEstimate(); long pos = player.getCurrentPosition(); long bufferedDuration = player.getBufferedPercentage() * player.getDuration() / 100; - eventEmitter.progressChanged(pos, bufferedDuration, player.getDuration()); + eventEmitter.progressChanged(pos, bufferedDuration, player.getDuration(), bitRateEstimate); msg = obtainMessage(SHOW_PROGRESS); sendMessageDelayed(msg, Math.round(mProgressUpdateInterval)); } @@ -542,6 +543,8 @@ class ReactExoplayerView extends FrameLayout implements audioTrack.putString("title", format.id != null ? format.id : ""); audioTrack.putString("type", format.sampleMimeType); audioTrack.putString("language", format.language != null ? format.language : ""); + audioTrack.putString("bitrate", format.bitrate == Format.NO_VALUE ? "" + : String.format(Locale.US, "%.2fMbps", format.bitrate / 1000000f)); audioTracks.pushMap(audioTrack); } return audioTracks; diff --git a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/VideoEventEmitter.java b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/VideoEventEmitter.java index fca24062..a7fa2436 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/VideoEventEmitter.java +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/VideoEventEmitter.java @@ -103,6 +103,7 @@ class VideoEventEmitter { private static final String EVENT_PROP_DURATION = "duration"; private static final String EVENT_PROP_PLAYABLE_DURATION = "playableDuration"; private static final String EVENT_PROP_SEEKABLE_DURATION = "seekableDuration"; + private static final String EVENT_PROP_BITRATE_ESTIMATE = "bitrateEstimate"; private static final String EVENT_PROP_CURRENT_TIME = "currentTime"; private static final String EVENT_PROP_SEEK_TIME = "seekTime"; private static final String EVENT_PROP_NATURAL_SIZE = "naturalSize"; @@ -163,11 +164,12 @@ class VideoEventEmitter { receiveEvent(EVENT_LOAD, event); } - void progressChanged(double currentPosition, double bufferedDuration, double seekableDuration) { + void progressChanged(double currentPosition, double bufferedDuration, double seekableDuration, double bitRateEstimate) { WritableMap event = Arguments.createMap(); event.putDouble(EVENT_PROP_CURRENT_TIME, currentPosition / 1000D); event.putDouble(EVENT_PROP_PLAYABLE_DURATION, bufferedDuration / 1000D); event.putDouble(EVENT_PROP_SEEKABLE_DURATION, seekableDuration / 1000D); + event.putDouble(EVENT_PROP_BITRATE_ESTIMATE, bitRateEstimate / 1000D); receiveEvent(EVENT_PROGRESS, event); }