Skip to content

Commit

Permalink
fix(android): video resolution orientation android (#3862)
Browse files Browse the repository at this point in the history
* fix(android): ensure width/heigh respect rotation of the video + Add rotation info in onVideoTrack event
  • Loading branch information
freeboub authored May 31, 2024
1 parent c2ce66e commit b698b18
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ class VideoTrack {
var index = -1
var trackId = ""
var isSelected = false
var rotation = 0
}
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ WritableArray videoTracksToArray(ArrayList<VideoTrack> videoTracks) {
videoTrack.putString("trackId", vTrack.getTrackId());
videoTrack.putInt("index", vTrack.getIndex());
videoTrack.putBoolean("selected", vTrack.isSelected());
videoTrack.putInt("rotation", vTrack.getRotation());
waVideoTracks.pushMap(videoTrack);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1375,8 +1375,9 @@ private void videoLoaded() {
setSelectedTextTrack(textTrackType, textTrackValue);
}
Format videoFormat = player.getVideoFormat();
int width = videoFormat != null ? videoFormat.width : 0;
int height = videoFormat != null ? videoFormat.height : 0;
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";

// Properties that must be accessed on the main thread
Expand Down Expand Up @@ -1444,6 +1445,7 @@ private VideoTrack exoplayerVideoTrackToGenericVideoTrack(Format format, int tra
videoTrack.setWidth(format.width == Format.NO_VALUE ? 0 : format.width);
videoTrack.setHeight(format.height == Format.NO_VALUE ? 0 : format.height);
videoTrack.setBitrate(format.bitrate == Format.NO_VALUE ? 0 : format.bitrate);
videoTrack.setRotation(format.rotationDegrees);
if (format.codecs != null) videoTrack.setCodecs(format.codecs);
videoTrack.setTrackId(format.id == null ? String.valueOf(trackIndex) : format.id);
videoTrack.setIndex(trackIndex);
Expand Down
20 changes: 11 additions & 9 deletions docs/pages/component/events.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -548,15 +548,16 @@ Callback function that is called when video tracks change

Payload:

| Property | Type | Description |
| -------- | ------- | ------------------------------------- |
| index | number | index of the track |
| trackId | string | Internal track ID |
| codecs | string | MimeType of codec used for this track |
| width | number | Track width |
| height | number | Track height |
| bitrate | number | Bitrate in bps |
| selected | boolean | true if track is selected for playing |
| Property | Type | Description |
| -------- | ------- | --------------------------------------------------------------- |
| index | number | index of the track |
| trackId | string | Internal track ID |
| codecs | string | MimeType of codec used for this track |
| width | number | Track width |
| height | number | Track height |
| bitrate | number | Bitrate in bps |
| selected | boolean | true if track is selected for playing |
| rotation | number | 0, 90, 180 or 270 rotation to apply to the track (android only) |

Example:

Expand All @@ -571,6 +572,7 @@ Example:
height: 1080,
bitrate: 10000,
selected: true,
rotation: 0,
},
];
}
Expand Down

0 comments on commit b698b18

Please sign in to comment.