Skip to content

Commit

Permalink
keep video aspect ratio for user specified texture size
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed Sep 8, 2024
1 parent 4f8b778 commit 085d199
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions lib/src/player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -181,17 +181,26 @@ class Player {
await FvpPlatform.instance.releaseTexture(nativeHandle, textureId.value!);
textureId.value = null;
}
final size = await _videoSize.future;
if (size == null) {
return -1;
}
if (width == null && height == null) {
// original size
final size = await _videoSize.future;
if (size == null) {
return -1;
}
textureId.value = await FvpPlatform.instance.createTexture(nativeHandle,
size.width.toInt(), size.height.toInt(), tunnel ?? false);
return textureId.value!;
}
if (width != null && height != null && width > 0 && height > 0) {
if (fit ?? true) {
final r = size.width / size.height;
final w = (height * r).toInt();
if (w <= width) {
width = w;
} else {
height = (width / r).toInt();
}
}
textureId.value = await FvpPlatform.instance
.createTexture(nativeHandle, width, height, tunnel ?? false);
return textureId.value!;
Expand Down

0 comments on commit 085d199

Please sign in to comment.