Skip to content

Commit a26491d

Browse files
committed
issue/130272: explicitly mark unstable api
1 parent 1e357b3 commit a26491d

File tree

1 file changed

+64
-34
lines changed
  • packages/video_player/video_player_android/android/src/main/java/io/flutter/plugins/videoplayer

1 file changed

+64
-34
lines changed

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

+64-34
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import android.net.Uri;
1212
import android.view.Surface;
1313
import androidx.annotation.NonNull;
14+
import androidx.annotation.Nullable;
1415
import androidx.annotation.OptIn;
1516
import androidx.annotation.VisibleForTesting;
1617
import androidx.media3.common.AudioAttributes;
@@ -42,9 +43,6 @@
4243
import java.util.List;
4344
import java.util.Map;
4445

45-
// API marked with UnstableApi is safe to use, it is only delicate when targeting stable ABI
46-
// https://developer.android.com/media/media3/exoplayer/migration-guide#unstableapi
47-
@OptIn(markerClass = UnstableApi.class)
4846
final class VideoPlayer {
4947
private static final String FORMAT_SS = "ss";
5048
private static final String FORMAT_DASH = "dash";
@@ -90,7 +88,7 @@ final class VideoPlayer {
9088

9189
MediaSource mediaSource = buildMediaSource(uri, dataSourceFactory, formatHint);
9290

93-
exoPlayer.setMediaSource(mediaSource);
91+
unstableSetMediaSource(exoPlayer, mediaSource);
9492
exoPlayer.prepare();
9593

9694
setUpVideoPlayer(exoPlayer, new QueuingEventSink());
@@ -121,11 +119,8 @@ public void buildHttpDataSourceFactory(@NonNull Map<String, String> httpHeaders)
121119
? httpHeaders.get(USER_AGENT)
122120
: "ExoPlayer";
123121

124-
httpDataSourceFactory.setUserAgent(userAgent).setAllowCrossProtocolRedirects(true);
125-
126-
if (httpHeadersNotEmpty) {
127-
httpDataSourceFactory.setDefaultRequestProperties(httpHeaders);
128-
}
122+
unstableUpdateDataSourceFactory(
123+
httpDataSourceFactory, httpHeaders, userAgent, httpHeadersNotEmpty);
129124
}
130125

131126
private MediaSource buildMediaSource(
@@ -152,26 +147,7 @@ private MediaSource buildMediaSource(
152147
break;
153148
}
154149
}
155-
switch (type) {
156-
case C.CONTENT_TYPE_SS:
157-
return new SsMediaSource.Factory(
158-
new DefaultSsChunkSource.Factory(mediaDataSourceFactory), mediaDataSourceFactory)
159-
.createMediaSource(MediaItem.fromUri(uri));
160-
case C.CONTENT_TYPE_DASH:
161-
return new DashMediaSource.Factory(
162-
new DefaultDashChunkSource.Factory(mediaDataSourceFactory), mediaDataSourceFactory)
163-
.createMediaSource(MediaItem.fromUri(uri));
164-
case C.CONTENT_TYPE_HLS:
165-
return new HlsMediaSource.Factory(mediaDataSourceFactory)
166-
.createMediaSource(MediaItem.fromUri(uri));
167-
case C.CONTENT_TYPE_OTHER:
168-
return new ProgressiveMediaSource.Factory(mediaDataSourceFactory)
169-
.createMediaSource(MediaItem.fromUri(uri));
170-
default:
171-
{
172-
throw new IllegalStateException("Unsupported type: " + type);
173-
}
174-
}
150+
return unstableBuildMediaSource(uri, mediaDataSourceFactory, type);
175151
}
176152

177153
private void setUpVideoPlayer(ExoPlayer exoPlayer, QueuingEventSink eventSink) {
@@ -309,15 +285,15 @@ void sendInitialized() {
309285
event.put("event", "initialized");
310286
event.put("duration", exoPlayer.getDuration());
311287

312-
if (exoPlayer.getVideoFormat() != null) {
313-
Format videoFormat = exoPlayer.getVideoFormat();
288+
Format videoFormat = unstableGetVideoFormat(exoPlayer);
289+
if (videoFormat != null) {
314290
int width = videoFormat.width;
315291
int height = videoFormat.height;
316-
int rotationDegrees = videoFormat.rotationDegrees;
292+
int rotationDegrees = unstableGetRotationDegrees(videoFormat);
317293
// Switch the width/height if video was taken in portrait mode
318294
if (rotationDegrees == 90 || rotationDegrees == 270) {
319-
width = exoPlayer.getVideoFormat().height;
320-
height = exoPlayer.getVideoFormat().width;
295+
width = videoFormat.height;
296+
height = videoFormat.width;
321297
}
322298
event.put("width", width);
323299
event.put("height", height);
@@ -348,4 +324,58 @@ void dispose() {
348324
exoPlayer.release();
349325
}
350326
}
327+
328+
@OptIn(markerClass = UnstableApi.class)
329+
private static void unstableSetMediaSource(ExoPlayer exoPlayer, MediaSource mediaSource) {
330+
exoPlayer.setMediaSource(mediaSource);
331+
}
332+
333+
@OptIn(markerClass = UnstableApi.class)
334+
private static void unstableUpdateDataSourceFactory(
335+
DefaultHttpDataSource.Factory factory,
336+
@NonNull Map<String, String> httpHeaders,
337+
String userAgent,
338+
boolean httpHeadersNotEmpty) {
339+
factory.setUserAgent(userAgent).setAllowCrossProtocolRedirects(true);
340+
341+
if (httpHeadersNotEmpty) {
342+
factory.setDefaultRequestProperties(httpHeaders);
343+
}
344+
}
345+
346+
@OptIn(markerClass = UnstableApi.class)
347+
private static MediaSource unstableBuildMediaSource(
348+
Uri uri, DataSource.Factory mediaDataSourceFactory, int type) {
349+
switch (type) {
350+
case C.CONTENT_TYPE_SS:
351+
return new SsMediaSource.Factory(
352+
new DefaultSsChunkSource.Factory(mediaDataSourceFactory), mediaDataSourceFactory)
353+
.createMediaSource(MediaItem.fromUri(uri));
354+
case C.CONTENT_TYPE_DASH:
355+
return new DashMediaSource.Factory(
356+
new DefaultDashChunkSource.Factory(mediaDataSourceFactory), mediaDataSourceFactory)
357+
.createMediaSource(MediaItem.fromUri(uri));
358+
case C.CONTENT_TYPE_HLS:
359+
return new HlsMediaSource.Factory(mediaDataSourceFactory)
360+
.createMediaSource(MediaItem.fromUri(uri));
361+
case C.CONTENT_TYPE_OTHER:
362+
return new ProgressiveMediaSource.Factory(mediaDataSourceFactory)
363+
.createMediaSource(MediaItem.fromUri(uri));
364+
default:
365+
{
366+
throw new IllegalStateException("Unsupported type: " + type);
367+
}
368+
}
369+
}
370+
371+
@OptIn(markerClass = UnstableApi.class)
372+
@Nullable
373+
private static Format unstableGetVideoFormat(ExoPlayer exoPlayer) {
374+
return exoPlayer.getVideoFormat();
375+
}
376+
377+
@OptIn(markerClass = UnstableApi.class)
378+
private static int unstableGetRotationDegrees(Format videoFormat) {
379+
return videoFormat.rotationDegrees;
380+
}
351381
}

0 commit comments

Comments
 (0)