Skip to content

Commit 582c2d3

Browse files
authored
[video_player_avplay] Automatically rotates video player based on device orientation (#817)
1 parent 9075a6e commit 582c2d3

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

packages/video_player_avplay/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.5.16
2+
3+
* Automatically rotates video player based on device orientation.
4+
15
## 0.5.15
26

37
* Fix dash player fail to seek issue.

packages/video_player_avplay/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ To use this package, add `video_player_avplay` as a dependency in your `pubspec.
1212

1313
```yaml
1414
dependencies:
15-
video_player_avplay: ^0.5.15
15+
video_player_avplay: ^0.5.16
1616
```
1717
1818
Then you can import `video_player_avplay` in your Dart code:

packages/video_player_avplay/lib/video_player.dart

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -994,13 +994,17 @@ class _VideoPlayerState extends State<VideoPlayer> {
994994
};
995995
}
996996

997+
MethodChannel windowChannel = const MethodChannel('tizen/internal/window');
998+
997999
late VoidCallback _listener;
9981000

9991001
late int _playerId;
10001002

10011003
final GlobalKey _videoBoxKey = GlobalKey();
10021004
Rect _playerRect = Rect.zero;
10031005

1006+
Orientation? _playerOrientation;
1007+
10041008
@override
10051009
void initState() {
10061010
super.initState();
@@ -1057,8 +1061,33 @@ class _VideoPlayerState extends State<VideoPlayer> {
10571061
widget.controller.removeListener(_listener);
10581062
}
10591063

1064+
Future<void> _updatePlayerOrientation() async {
1065+
final Orientation orientation = MediaQuery.orientationOf(context);
1066+
int? rotate;
1067+
if (widget.controller.value.isInitialized &&
1068+
(_playerOrientation == null || _playerOrientation != orientation)) {
1069+
rotate = await windowChannel.invokeMethod('getRotation');
1070+
_playerOrientation = orientation;
1071+
}
1072+
1073+
if (rotate == null) {
1074+
return;
1075+
}
1076+
1077+
if (rotate == 90) {
1078+
await widget.controller.setDisplayRotate(DisplayRotation.rotation270);
1079+
} else if (rotate == 180) {
1080+
await widget.controller.setDisplayRotate(DisplayRotation.rotation180);
1081+
} else if (rotate == 270) {
1082+
await widget.controller.setDisplayRotate(DisplayRotation.rotation90);
1083+
} else {
1084+
await widget.controller.setDisplayRotate(DisplayRotation.rotation0);
1085+
}
1086+
}
1087+
10601088
@override
10611089
Widget build(BuildContext context) {
1090+
_updatePlayerOrientation();
10621091
return Container(key: _videoBoxKey, child: const Hole());
10631092
}
10641093
}

packages/video_player_avplay/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: video_player_avplay
22
description: Flutter plugin for displaying inline video on Tizen TV devices.
33
homepage: https://github.com/flutter-tizen/plugins
44
repository: https://github.com/flutter-tizen/plugins/tree/master/packages/video_player_avplay
5-
version: 0.5.15
5+
version: 0.5.16
66

77
environment:
88
sdk: ">=3.1.0 <4.0.0"

0 commit comments

Comments
 (0)