Skip to content
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

[video_player_android] Platform view support #8466

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
15a0d09
Add platform interface changes
FirentisTFW Jan 21, 2025
25520fc
Add platform view support for Android
FirentisTFW Jan 21, 2025
28d38c5
Rearrange native unit tests after merge
FirentisTFW Jan 21, 2025
0d3a753
Remove a todo in web implementation
FirentisTFW Jan 21, 2025
ea16d63
Set initial value of nextNonTexturePlayerId to Long.MAX_VALUE
FirentisTFW Jan 21, 2025
25425ca
Use player provider instead of modifiable list
FirentisTFW Jan 21, 2025
ce2aa51
Remove empty line
FirentisTFW Jan 21, 2025
8aeca10
Check player view states in Dart unit tests
FirentisTFW Jan 21, 2025
209f34f
Restore previous formatting for comments
FirentisTFW Jan 21, 2025
42cb659
Add missing licenses
FirentisTFW Jan 21, 2025
690ec54
Format files
FirentisTFW Jan 21, 2025
6db9e6d
Fix linting issues
FirentisTFW Jan 21, 2025
277bff7
Rename textureId to playerId in platform interace methods
FirentisTFW Jan 21, 2025
5aca5db
Rename textureId to playerId in Android Dart files
FirentisTFW Jan 21, 2025
751d529
Rename textureId to playerId in Android native code
FirentisTFW Jan 21, 2025
e6f856b
Add an ignore to UI test (it times out on Firebase Test Lab)
FirentisTFW Jan 21, 2025
b752b4c
Merge branch 'main' into feature/video-player-android-platform-view-s…
FirentisTFW Jan 28, 2025
8fc1fa0
Bump platform interface dependency to 6.3.0
FirentisTFW Jan 28, 2025
b745dcc
Remove resolved todo and fix dartdocs
FirentisTFW Jan 28, 2025
773cfc1
Add missing import
FirentisTFW Jan 28, 2025
89dfcea
Format test file
FirentisTFW Jan 28, 2025
f59463a
Add more context to class names for native views
FirentisTFW Jan 28, 2025
650cc21
Add missing docs for Android
FirentisTFW Jan 28, 2025
18463e7
Format file
FirentisTFW Jan 28, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/video_player/video_player_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## NEXT
## 2.8.0

* Adds support for platform views as an optional way of displaying a video.
* Suppresses deprecation and removal warnings for
`TextureRegistry.SurfaceProducer.onSurfaceDestroyed`.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
import androidx.media3.common.PlaybackException;
import androidx.media3.common.Player;
import androidx.media3.common.VideoSize;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.exoplayer.ExoPlayer;
import java.util.Objects;

final class ExoPlayerEventListener implements Player.Listener {
private final ExoPlayer exoPlayer;
private final VideoPlayerCallbacks events;
private final Messages.PlatformVideoViewType viewType;
private boolean isBuffering = false;
private boolean isInitialized;

Expand Down Expand Up @@ -46,13 +48,19 @@ public int getDegrees() {
}
}

ExoPlayerEventListener(ExoPlayer exoPlayer, VideoPlayerCallbacks events) {
this(exoPlayer, events, false);
ExoPlayerEventListener(
ExoPlayer exoPlayer, VideoPlayerCallbacks events, Messages.PlatformVideoViewType viewType) {
this(exoPlayer, events, viewType, false);
}

ExoPlayerEventListener(ExoPlayer exoPlayer, VideoPlayerCallbacks events, boolean initialized) {
ExoPlayerEventListener(
ExoPlayer exoPlayer,
VideoPlayerCallbacks events,
Messages.PlatformVideoViewType viewType,
boolean initialized) {
this.exoPlayer = exoPlayer;
this.events = events;
this.viewType = viewType;
this.isInitialized = initialized;
}

Expand All @@ -74,6 +82,36 @@ private void sendInitialized() {
return;
}
isInitialized = true;

if (viewType == Messages.PlatformVideoViewType.PLATFORM_VIEW) {
sendInitializedForPlatformViewBased();
} else {
sendInitializedForTextureBased();
}
}

@OptIn(markerClass = UnstableApi.class)
private void sendInitializedForPlatformViewBased() {
// We can't rely on VideoSize here, because at this point it is not available - the platform
// view was not created yet. We use the video format instead.
Format videoFormat = exoPlayer.getVideoFormat();
RotationDegrees rotationCorrection =
RotationDegrees.fromDegrees(Objects.requireNonNull(videoFormat).rotationDegrees);
int width = videoFormat.width;
int height = videoFormat.height;

if (rotationCorrection == RotationDegrees.ROTATE_90
|| rotationCorrection == RotationDegrees.ROTATE_270) {
width = videoFormat.height;
height = videoFormat.width;

rotationCorrection = RotationDegrees.fromDegrees(0);
}

events.onInitialized(width, height, exoPlayer.getDuration(), rotationCorrection.getDegrees());
}

private void sendInitializedForTextureBased() {
VideoSize videoSize = exoPlayer.getVideoSize();
int rotationCorrection = 0;
int width = videoSize.width;
Expand Down
Loading