Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
[video_player] Platform interface changes to fix Android rotation for…
Browse files Browse the repository at this point in the history
… videos recorded in landscapeRight (#4634)
  • Loading branch information
KyleFin authored Mar 22, 2022
1 parent 3069bc3 commit 52995e8
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 5.1.1

* Adds `rotationCorrection` (for Android playing videos recorded in landscapeRight [#60327](https://github.com/flutter/flutter/issues/60327)).

## 5.1.0

* Adds `allowBackgroundPlayback` to `VideoPlayerOptions`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class MethodChannelVideoPlayer extends VideoPlayerPlatform {
duration: Duration(milliseconds: map['duration']! as int),
size: Size((map['width'] as num?)?.toDouble() ?? 0.0,
(map['height'] as num?)?.toDouble() ?? 0.0),
rotationCorrection: map['rotationCorrection'] as int? ?? 0,
);
case 'completed':
return VideoEvent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ class VideoEvent {
///
/// The [eventType] argument is required.
///
/// Depending on the [eventType], the [duration], [size] and [buffered]
/// arguments can be null.
/// Depending on the [eventType], the [duration], [size],
/// [rotationCorrection], and [buffered] arguments can be null.
// TODO(stuartmorgan): Temporarily suppress warnings about not using const
// in all of the other video player packages, fix this, and then update
// the other packages to use const.
Expand All @@ -209,6 +209,7 @@ class VideoEvent {
required this.eventType,
this.duration,
this.size,
this.rotationCorrection,
this.buffered,
});

Expand All @@ -225,6 +226,11 @@ class VideoEvent {
/// Only used if [eventType] is [VideoEventType.initialized].
final Size? size;

/// Degrees to rotate the video (clockwise) so it is displayed correctly.
///
/// Only used if [eventType] is [VideoEventType.initialized].
final int? rotationCorrection;

/// Buffered parts of the video.
///
/// Only used if [eventType] is [VideoEventType.bufferingUpdate].
Expand All @@ -238,6 +244,7 @@ class VideoEvent {
eventType == other.eventType &&
duration == other.duration &&
size == other.size &&
rotationCorrection == other.rotationCorrection &&
listEquals(buffered, other.buffered);
}

Expand All @@ -246,6 +253,7 @@ class VideoEvent {
eventType.hashCode ^
duration.hashCode ^
size.hashCode ^
rotationCorrection.hashCode ^
buffered.hashCode;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ repository: https://github.com/flutter/plugins/tree/main/packages/video_player/v
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
version: 5.1.0
version: 5.1.1

environment:
sdk: ">=2.12.0 <3.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,20 @@ void main() {
}),
(ByteData? data) {});

await _ambiguate(ServicesBinding.instance)
?.defaultBinaryMessenger
.handlePlatformMessage(
'flutter.io/videoPlayer/videoEvents123',
const StandardMethodCodec()
.encodeSuccessEnvelope(<String, dynamic>{
'event': 'initialized',
'duration': 98765,
'width': 1920,
'height': 1080,
'rotationCorrection': 180,
}),
(ByteData? data) {});

await _ambiguate(ServicesBinding.instance)
?.defaultBinaryMessenger
.handlePlatformMessage(
Expand Down Expand Up @@ -316,6 +330,13 @@ void main() {
eventType: VideoEventType.initialized,
duration: const Duration(milliseconds: 98765),
size: const Size(1920, 1080),
rotationCorrection: 0,
),
VideoEvent(
eventType: VideoEventType.initialized,
duration: const Duration(milliseconds: 98765),
size: const Size(1920, 1080),
rotationCorrection: 180,
),
VideoEvent(eventType: VideoEventType.completed),
VideoEvent(
Expand Down

0 comments on commit 52995e8

Please sign in to comment.