-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[video_player_android] Correct rotation of videos recorded by the camera #7846
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
5b8ad64
debugging
camsim99 bbac0c3
theoretical fix
camsim99 43898cb
Mild cleanup
camsim99 95d5e43
Undo extra import
camsim99 3306352
Fix logic + start tests
camsim99 3524885
Merge remote-tracking branch 'upstream/main' into vp_fix
camsim99 2664b51
Fix code + add tests
camsim99 1ba7efc
Remove print statement, bump version
camsim99 0ff09c6
Add Impeller case
camsim99 a374698
Merge remote-tracking branch 'upstream/main' into vp_fix
camsim99 a74cea9
Cleanup
camsim99 da92163
Add comment
camsim99 1a65eea
Correct changelog
camsim99 ee0f7de
Address review
camsim99 fc22ee6
Merge remote-tracking branch 'upstream/main' into vp_fix
camsim99 5f2a824
address review
camsim99 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix code + add tests
- Loading branch information
commit 2664b51063017bf5f2a97cfa19e7fc4ccb4b3031
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,8 @@ | |
|
|
||
| import android.os.Build; | ||
| import androidx.annotation.NonNull; | ||
| import androidx.annotation.OptIn; | ||
| import androidx.media3.common.Format; | ||
| import androidx.media3.common.PlaybackException; | ||
| import androidx.media3.common.Player; | ||
| import androidx.media3.common.VideoSize; | ||
|
|
@@ -42,29 +44,34 @@ private void setBuffering(boolean buffering) { | |
|
|
||
| @SuppressWarnings("SuspiciousNameCombination") | ||
| private void sendInitialized() { | ||
| System.out.println("Hello???"); | ||
| if (isInitialized) { | ||
| return; | ||
| } | ||
| isInitialized = true; | ||
| VideoSize videoSize = exoPlayer.getVideoSize(); | ||
| int rotationCorrection = 0; | ||
| int width = videoSize.width; | ||
| int height = videoSize.height; | ||
| int rotationCorrection = 0; | ||
| if (width != 0 && height != 0) { | ||
| int reportedRotationCorrection; | ||
|
|
||
| if (Build.VERSION.SDK_INT <= 21) { | ||
| // On API 21 and below, Exoplayer may not internally handle rotation correction | ||
| // and reports it through VideoSize.unappliedRotationDegrees. | ||
| rotationCorrection = getRotationCorrectionFromUnappliedRotation(videoSize); | ||
| // and reports it through VideoSize.unappliedRotationDegrees. We may apply it to | ||
| // fix the case of upside-down playback. | ||
| reportedRotationCorrection = videoSize.unappliedRotationDegrees; | ||
| rotationCorrection = getRotationCorrectionFromUnappliedRotation(reportedRotationCorrection); | ||
| } else { | ||
| // Above API 21, Exoplayer handles the VideoSize.unappliedRotationDegrees | ||
| // correction internally. However, the video's Format also provides a rotation | ||
| // correction that may be used to correct the rotation, so we try to use that. | ||
| Format videoFormat = Objects.requireNonNull(exoPlayer.getVideoFormat()); | ||
| rotationCorrection = getRotationCorrectionFromFormat(videoFormat); | ||
| rotationCorrection = getRotationCorrectionFromFormat(exoPlayer); | ||
| reportedRotationCorrection = rotationCorrection; | ||
| } | ||
|
|
||
| // Switch the width/height if video was taken in portrait mode. | ||
| if (rotationDegrees == 90 || rotationDegrees == 270) { | ||
| if (reportedRotationCorrection == 90 || reportedRotationCorrection == 270) { | ||
camsim99 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| width = videoSize.height; | ||
| height = videoSize.width; | ||
| } | ||
|
|
@@ -73,22 +80,23 @@ private void sendInitialized() { | |
| events.onInitialized(width, height, exoPlayer.getDuration(), rotationCorrection); | ||
| } | ||
|
|
||
| private int getRotationCorrectionFromUnappliedRotation(VideoSize videoSize) { | ||
| int rotationCorrection = 0; | ||
| int unappliedRotationDegrees = videoSize.unappliedRotationDegrees; | ||
| private int getRotationCorrectionFromUnappliedRotation(int unappliedRotationDegrees) { | ||
|
||
| int rotationCorrection = 0; | ||
|
|
||
| // Rotating the video with ExoPlayer does not seem to be possible with a Surface, | ||
| // so inform the Flutter code that the widget needs to be rotated to prevent | ||
| // upside-down playback for videos with unappliedRotationDegrees of 180 (other orientations | ||
| // work correctly without correction). | ||
| if (unappliedRotationDegrees == 180) { | ||
| rotationCorrection = unappliedRotationDegrees; | ||
| } | ||
| // Rotating the video with ExoPlayer does not seem to be possible with a Surface, | ||
| // so inform the Flutter code that the widget needs to be rotated to prevent | ||
| // upside-down playback for videos with unappliedRotationDegrees of 180 (other orientations | ||
| // work correctly without correction). | ||
| if (unappliedRotationDegrees == 180) { | ||
| rotationCorrection = unappliedRotationDegrees; | ||
| } | ||
|
|
||
| return rotationCorrection; | ||
| } | ||
|
|
||
| private int getRotationCorrectionFromFormat(Format videoFormat) { | ||
| @OptIn(markerClass = androidx.media3.common.util.UnstableApi.class) | ||
| private int getRotationCorrectionFromFormat(ExoPlayer exoPlayer) { | ||
| Format videoFormat = Objects.requireNonNull(exoPlayer.getVideoFormat()); | ||
| return videoFormat.rotationDegrees; | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.