Skip to content

Commit

Permalink
issue/130272: migrate unstable api: replace video Format with VideoSize
Browse files Browse the repository at this point in the history
  • Loading branch information
emakar committed Jun 5, 2024
1 parent 53c90b9 commit ef48514
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
import androidx.annotation.VisibleForTesting;
import androidx.media3.common.AudioAttributes;
import androidx.media3.common.C;
import androidx.media3.common.Format;
import androidx.media3.common.MediaItem;
import androidx.media3.common.MimeTypes;
import androidx.media3.common.PlaybackException;
import androidx.media3.common.PlaybackParameters;
import androidx.media3.common.Player;
import androidx.media3.common.Player.Listener;
import androidx.media3.common.VideoSize;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.datasource.DataSource;
import androidx.media3.datasource.DefaultDataSource;
Expand Down Expand Up @@ -295,15 +295,15 @@ void sendInitialized() {
event.put("event", "initialized");
event.put("duration", exoPlayer.getDuration());

Format videoFormat = unstableGetVideoFormat(exoPlayer);
if (videoFormat != null) {
int width = videoFormat.width;
int height = videoFormat.height;
int rotationDegrees = unstableGetRotationDegrees(videoFormat);
VideoSize videoSize = exoPlayer.getVideoSize();
int width = videoSize.width;
int height = videoSize.height;
if (width != 0 && height != 0) {
int rotationDegrees = videoSize.unappliedRotationDegrees;
// Switch the width/height if video was taken in portrait mode
if (rotationDegrees == 90 || rotationDegrees == 270) {
width = videoFormat.height;
height = videoFormat.width;
width = videoSize.height;
height = videoSize.width;
}
event.put("width", width);
event.put("height", height);
Expand Down Expand Up @@ -363,17 +363,4 @@ private static void unstableUpdateDataSourceFactory(
factory.setDefaultRequestProperties(httpHeaders);
}
}

// TODO: migrate to stable API, see https://github.com/flutter/flutter/issues/147039
@OptIn(markerClass = UnstableApi.class)
@Nullable
private static Format unstableGetVideoFormat(ExoPlayer exoPlayer) {
return exoPlayer.getVideoFormat();
}

// TODO: migrate to stable API, see https://github.com/flutter/flutter/issues/147039
@OptIn(markerClass = UnstableApi.class)
private static int unstableGetRotationDegrees(Format videoFormat) {
return videoFormat.rotationDegrees;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;

import androidx.media3.common.Format;
import androidx.media3.common.PlaybackException;
import androidx.media3.common.Player;
import androidx.media3.common.VideoSize;
import androidx.media3.datasource.DefaultHttpDataSource;
import androidx.media3.exoplayer.ExoPlayer;
import io.flutter.plugin.common.EventChannel;
Expand Down Expand Up @@ -135,10 +135,9 @@ public void sendInitializedSendsExpectedEvent_90RotationDegrees() {
fakeVideoPlayerOptions,
fakeEventSink,
httpDataSourceFactorySpy);
Format testFormat =
new Format.Builder().setWidth(100).setHeight(200).setRotationDegrees(90).build();
VideoSize testVideoSize = new VideoSize(100, 200, 90, 1f);

when(fakeExoPlayer.getVideoFormat()).thenReturn(testFormat);
when(fakeExoPlayer.getVideoSize()).thenReturn(testVideoSize);
when(fakeExoPlayer.getDuration()).thenReturn(10L);

videoPlayer.isInitialized = true;
Expand All @@ -164,10 +163,9 @@ public void sendInitializedSendsExpectedEvent_270RotationDegrees() {
fakeVideoPlayerOptions,
fakeEventSink,
httpDataSourceFactorySpy);
Format testFormat =
new Format.Builder().setWidth(100).setHeight(200).setRotationDegrees(270).build();
VideoSize testVideoSize = new VideoSize(100, 200, 270, 1f);

when(fakeExoPlayer.getVideoFormat()).thenReturn(testFormat);
when(fakeExoPlayer.getVideoSize()).thenReturn(testVideoSize);
when(fakeExoPlayer.getDuration()).thenReturn(10L);

videoPlayer.isInitialized = true;
Expand All @@ -193,10 +191,9 @@ public void sendInitializedSendsExpectedEvent_0RotationDegrees() {
fakeVideoPlayerOptions,
fakeEventSink,
httpDataSourceFactorySpy);
Format testFormat =
new Format.Builder().setWidth(100).setHeight(200).setRotationDegrees(0).build();
VideoSize testVideoSize = new VideoSize(100, 200, 0, 1f);

when(fakeExoPlayer.getVideoFormat()).thenReturn(testFormat);
when(fakeExoPlayer.getVideoSize()).thenReturn(testVideoSize);
when(fakeExoPlayer.getDuration()).thenReturn(10L);

videoPlayer.isInitialized = true;
Expand All @@ -222,10 +219,9 @@ public void sendInitializedSendsExpectedEvent_180RotationDegrees() {
fakeVideoPlayerOptions,
fakeEventSink,
httpDataSourceFactorySpy);
Format testFormat =
new Format.Builder().setWidth(100).setHeight(200).setRotationDegrees(180).build();
VideoSize testVideoSize = new VideoSize(100, 200, 180, 1f);

when(fakeExoPlayer.getVideoFormat()).thenReturn(testFormat);
when(fakeExoPlayer.getVideoSize()).thenReturn(testVideoSize);
when(fakeExoPlayer.getDuration()).thenReturn(10L);

videoPlayer.isInitialized = true;
Expand Down

0 comments on commit ef48514

Please sign in to comment.