Skip to content

Commit 78b87ee

Browse files
committed
issue/130272: migrate unstable api: replace video Format with VideoSize
1 parent c2b31bc commit 78b87ee

File tree

2 files changed

+17
-34
lines changed

2 files changed

+17
-34
lines changed

packages/video_player/video_player_android/android/src/main/java/io/flutter/plugins/videoplayer/VideoPlayer.java

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
import androidx.annotation.VisibleForTesting;
1515
import androidx.media3.common.AudioAttributes;
1616
import androidx.media3.common.C;
17-
import androidx.media3.common.Format;
1817
import androidx.media3.common.MediaItem;
1918
import androidx.media3.common.MimeTypes;
2019
import androidx.media3.common.PlaybackException;
2120
import androidx.media3.common.PlaybackParameters;
2221
import androidx.media3.common.Player;
2322
import androidx.media3.common.Player.Listener;
23+
import androidx.media3.common.VideoSize;
2424
import androidx.media3.common.util.UnstableApi;
2525
import androidx.media3.datasource.DataSource;
2626
import androidx.media3.datasource.DefaultDataSource;
@@ -298,15 +298,15 @@ void sendInitialized() {
298298
event.put("event", "initialized");
299299
event.put("duration", exoPlayer.getDuration());
300300

301-
Format videoFormat = unstableGetVideoFormat(exoPlayer);
302-
if (videoFormat != null) {
303-
int width = videoFormat.width;
304-
int height = videoFormat.height;
305-
int rotationDegrees = unstableGetRotationDegrees(videoFormat);
301+
VideoSize videoSize = exoPlayer.getVideoSize();
302+
int width = videoSize.width;
303+
int height = videoSize.height;
304+
if (width != 0 && height != 0) {
305+
int rotationDegrees = videoSize.unappliedRotationDegrees;
306306
// Switch the width/height if video was taken in portrait mode
307307
if (rotationDegrees == 90 || rotationDegrees == 270) {
308-
width = videoFormat.height;
309-
height = videoFormat.width;
308+
width = videoSize.height;
309+
height = videoSize.width;
310310
}
311311
event.put("width", width);
312312
event.put("height", height);
@@ -366,17 +366,4 @@ private static void unstableUpdateDataSourceFactory(
366366
factory.setDefaultRequestProperties(httpHeaders);
367367
}
368368
}
369-
370-
// TODO: migrate to stable API, see https://github.com/flutter/flutter/issues/147039
371-
@OptIn(markerClass = UnstableApi.class)
372-
@Nullable
373-
private static Format unstableGetVideoFormat(ExoPlayer exoPlayer) {
374-
return exoPlayer.getVideoFormat();
375-
}
376-
377-
// TODO: migrate to stable API, see https://github.com/flutter/flutter/issues/147039
378-
@OptIn(markerClass = UnstableApi.class)
379-
private static int unstableGetRotationDegrees(Format videoFormat) {
380-
return videoFormat.rotationDegrees;
381-
}
382369
}

packages/video_player/video_player_android/android/src/test/java/io/flutter/plugins/videoplayer/VideoPlayerTest.java

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
import static org.mockito.Mockito.spy;
1414
import static org.mockito.Mockito.times;
1515

16-
import androidx.media3.common.Format;
1716
import androidx.media3.common.PlaybackException;
1817
import androidx.media3.common.Player;
18+
import androidx.media3.common.VideoSize;
1919
import androidx.media3.datasource.DefaultHttpDataSource;
2020
import androidx.media3.exoplayer.ExoPlayer;
2121
import io.flutter.plugin.common.EventChannel;
@@ -135,10 +135,9 @@ public void sendInitializedSendsExpectedEvent_90RotationDegrees() {
135135
fakeVideoPlayerOptions,
136136
fakeEventSink,
137137
httpDataSourceFactorySpy);
138-
Format testFormat =
139-
new Format.Builder().setWidth(100).setHeight(200).setRotationDegrees(90).build();
138+
VideoSize testVideoSize = new VideoSize(100, 200, 90, 1f);
140139

141-
when(fakeExoPlayer.getVideoFormat()).thenReturn(testFormat);
140+
when(fakeExoPlayer.getVideoSize()).thenReturn(testVideoSize);
142141
when(fakeExoPlayer.getDuration()).thenReturn(10L);
143142

144143
videoPlayer.isInitialized = true;
@@ -164,10 +163,9 @@ public void sendInitializedSendsExpectedEvent_270RotationDegrees() {
164163
fakeVideoPlayerOptions,
165164
fakeEventSink,
166165
httpDataSourceFactorySpy);
167-
Format testFormat =
168-
new Format.Builder().setWidth(100).setHeight(200).setRotationDegrees(270).build();
166+
VideoSize testVideoSize = new VideoSize(100, 200, 270, 1f);
169167

170-
when(fakeExoPlayer.getVideoFormat()).thenReturn(testFormat);
168+
when(fakeExoPlayer.getVideoSize()).thenReturn(testVideoSize);
171169
when(fakeExoPlayer.getDuration()).thenReturn(10L);
172170

173171
videoPlayer.isInitialized = true;
@@ -193,10 +191,9 @@ public void sendInitializedSendsExpectedEvent_0RotationDegrees() {
193191
fakeVideoPlayerOptions,
194192
fakeEventSink,
195193
httpDataSourceFactorySpy);
196-
Format testFormat =
197-
new Format.Builder().setWidth(100).setHeight(200).setRotationDegrees(0).build();
194+
VideoSize testVideoSize = new VideoSize(100, 200, 0, 1f);
198195

199-
when(fakeExoPlayer.getVideoFormat()).thenReturn(testFormat);
196+
when(fakeExoPlayer.getVideoSize()).thenReturn(testVideoSize);
200197
when(fakeExoPlayer.getDuration()).thenReturn(10L);
201198

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

228-
when(fakeExoPlayer.getVideoFormat()).thenReturn(testFormat);
224+
when(fakeExoPlayer.getVideoSize()).thenReturn(testVideoSize);
229225
when(fakeExoPlayer.getDuration()).thenReturn(10L);
230226

231227
videoPlayer.isInitialized = true;

0 commit comments

Comments
 (0)