chore(android): add null check for id of videoFormat (#4174)
* chore(android): add null check for id of videoFormat * chore: null check videoFormat.id on onBandwidthSample * fix: PR feedback * fix: linter error * chore: update trackId fallback value
This commit is contained in:
committed by
GitHub
parent
0538b3b468
commit
1ef2b3a977
@@ -64,11 +64,11 @@ class VideoEventEmitter {
|
||||
audioTracks: ArrayList<Track>,
|
||||
textTracks: ArrayList<Track>,
|
||||
videoTracks: ArrayList<VideoTrack>,
|
||||
trackId: String
|
||||
trackId: String?
|
||||
) -> Unit
|
||||
lateinit var onVideoError: (errorString: String, exception: Exception, errorCode: String) -> Unit
|
||||
lateinit var onVideoProgress: (currentPosition: Long, bufferedDuration: Long, seekableDuration: Long, currentPlaybackTime: Double) -> Unit
|
||||
lateinit var onVideoBandwidthUpdate: (bitRateEstimate: Long, height: Int, width: Int, trackId: String) -> Unit
|
||||
lateinit var onVideoBandwidthUpdate: (bitRateEstimate: Long, height: Int, width: Int, trackId: String?) -> Unit
|
||||
lateinit var onVideoPlaybackStateChanged: (isPlaying: Boolean, isSeeking: Boolean) -> Unit
|
||||
lateinit var onVideoSeek: (currentPosition: Long, seekTime: Long) -> Unit
|
||||
lateinit var onVideoEnd: () -> Unit
|
||||
@@ -108,7 +108,7 @@ class VideoEventEmitter {
|
||||
|
||||
val naturalSize: WritableMap = aspectRatioToNaturalSize(videoWidth, videoHeight)
|
||||
putMap("naturalSize", naturalSize)
|
||||
putString("trackId", trackId)
|
||||
trackId?.let { putString("trackId", it) }
|
||||
putArray("videoTracks", videoTracksToArray(videoTracks))
|
||||
putArray("audioTracks", audioTracksToArray(audioTracks))
|
||||
putArray("textTracks", textTracksToArray(textTracks))
|
||||
@@ -153,9 +153,13 @@ class VideoEventEmitter {
|
||||
onVideoBandwidthUpdate = { bitRateEstimate, height, width, trackId ->
|
||||
event.dispatch(EventTypes.EVENT_BANDWIDTH) {
|
||||
putDouble("bitrate", bitRateEstimate.toDouble())
|
||||
putInt("width", width)
|
||||
putInt("height", height)
|
||||
putString("trackId", trackId)
|
||||
if (width > 0) {
|
||||
putInt("width", width)
|
||||
}
|
||||
if (height > 0) {
|
||||
putInt("height", height)
|
||||
}
|
||||
trackId?.let { putString("trackId", it) }
|
||||
}
|
||||
}
|
||||
onVideoPlaybackStateChanged = { isPlaying, isSeeking ->
|
||||
@@ -336,15 +340,19 @@ class VideoEventEmitter {
|
||||
|
||||
private fun aspectRatioToNaturalSize(videoWidth: Int, videoHeight: Int): WritableMap =
|
||||
Arguments.createMap().apply {
|
||||
putInt("width", videoWidth)
|
||||
putInt("height", videoHeight)
|
||||
val orientation = if (videoWidth > videoHeight) {
|
||||
"landscape"
|
||||
} else if (videoWidth < videoHeight) {
|
||||
"portrait"
|
||||
} else {
|
||||
"square"
|
||||
if (videoWidth > 0) {
|
||||
putInt("width", videoWidth)
|
||||
}
|
||||
if (videoHeight > 0) {
|
||||
putInt("height", videoHeight)
|
||||
}
|
||||
|
||||
val orientation = when {
|
||||
videoWidth > videoHeight -> "landscape"
|
||||
videoWidth < videoHeight -> "portrait"
|
||||
else -> "square"
|
||||
}
|
||||
|
||||
putString("orientation", orientation)
|
||||
}
|
||||
}
|
||||
|
@@ -139,7 +139,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
@@ -385,12 +384,13 @@ public class ReactExoplayerView extends FrameLayout implements
|
||||
public void onBandwidthSample(int elapsedMs, long bytes, long bitrate) {
|
||||
if (mReportBandwidth) {
|
||||
if (player == null) {
|
||||
eventEmitter.onVideoBandwidthUpdate.invoke(bitrate, 0, 0, "-1");
|
||||
eventEmitter.onVideoBandwidthUpdate.invoke(bitrate, 0, 0, null);
|
||||
} else {
|
||||
Format videoFormat = player.getVideoFormat();
|
||||
int width = videoFormat != null ? videoFormat.width : 0;
|
||||
int height = videoFormat != null ? videoFormat.height : 0;
|
||||
String trackId = videoFormat != null ? videoFormat.id : "-1";
|
||||
boolean isRotatedContent = videoFormat != null && (videoFormat.rotationDegrees == 90 || videoFormat.rotationDegrees == 270);
|
||||
int width = videoFormat != null ? (isRotatedContent ? videoFormat.height : videoFormat.width) : 0;
|
||||
int height = videoFormat != null ? (isRotatedContent ? videoFormat.width : videoFormat.height) : 0;
|
||||
String trackId = videoFormat != null ? videoFormat.id : null;
|
||||
eventEmitter.onVideoBandwidthUpdate.invoke(bitrate, height, width, trackId);
|
||||
}
|
||||
}
|
||||
@@ -1427,7 +1427,7 @@ public class ReactExoplayerView extends FrameLayout implements
|
||||
boolean isRotatedContent = videoFormat != null && (videoFormat.rotationDegrees == 90 || videoFormat.rotationDegrees == 270);
|
||||
int width = videoFormat != null ? (isRotatedContent ? videoFormat.height : videoFormat.width) : 0;
|
||||
int height = videoFormat != null ? (isRotatedContent ? videoFormat.width : videoFormat.height) : 0;
|
||||
String trackId = videoFormat != null ? videoFormat.id : "-1";
|
||||
String trackId = videoFormat != null ? videoFormat.id : null;
|
||||
|
||||
// Properties that must be accessed on the main thread
|
||||
long duration = player.getDuration();
|
||||
|
Reference in New Issue
Block a user