Skip to content

[video_player] Platform view support #8810

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
Show file tree
Hide file tree
Changes from all commits
Commits
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/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## NEXT
## 2.10.0

* Adds support for platform views as an optional way of displaying a video on Android and iOS.
* Updates README to indicate that Andoid SDK <21 is no longer supported.
* Updates minimum supported SDK version to Flutter 3.27/Dart 3.6.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latest version of video_player_android requires such constraints


Expand Down
7 changes: 7 additions & 0 deletions packages/video_player/video_player/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,10 @@ and so on.
To learn about playback speed limitations, see the [`setPlaybackSpeed` method documentation](https://pub.dev/documentation/video_player/latest/video_player/VideoPlayerController/setPlaybackSpeed.html).

Furthermore, see the example app for an example playback speed implementation.

### Video view type

You can set the video view type of your controller (instance of `VideoPlayerController`) during its creation by passing the `videoViewType` argument.
If set to `VideoViewType.platformView`, platform views will be used instead of texture view on supported platforms.

The relative performance of the different view types may vary by platform, and on some platforms the use of platform views may have correctness issues in certain circumstances due to limitations of Flutter's platform view system.
94 changes: 89 additions & 5 deletions packages/video_player/video_player/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,89 @@ class _App extends StatelessWidget {
),
body: TabBarView(
children: <Widget>[
_BumbleBeeRemoteVideo(),
_ButterFlyAssetVideo(),
_ButterFlyAssetVideoInList(),
_ViewTypeTabBar(
builder: (VideoViewType viewType) =>
_BumbleBeeRemoteVideo(viewType),
),
_ViewTypeTabBar(
builder: (VideoViewType viewType) =>
_ButterFlyAssetVideo(viewType),
),
_ViewTypeTabBar(
builder: (VideoViewType viewType) =>
_ButterFlyAssetVideoInList(viewType),
),
],
),
),
);
}
}

class _ViewTypeTabBar extends StatefulWidget {
const _ViewTypeTabBar({
required this.builder,
});

final Widget Function(VideoViewType) builder;

@override
State<_ViewTypeTabBar> createState() => _ViewTypeTabBarState();
}

class _ViewTypeTabBarState extends State<_ViewTypeTabBar>
with SingleTickerProviderStateMixin {
late final TabController _tabController;

@override
void initState() {
super.initState();
_tabController = TabController(length: 2, vsync: this);
}

@override
void dispose() {
_tabController.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
TabBar(
controller: _tabController,
isScrollable: true,
tabs: const <Widget>[
Tab(
icon: Icon(Icons.texture),
text: 'Texture view',
),
Tab(
icon: Icon(Icons.construction),
text: 'Platform view',
),
],
),
Expanded(
child: TabBarView(
controller: _tabController,
children: <Widget>[
widget.builder(VideoViewType.textureView),
widget.builder(VideoViewType.platformView),
],
),
),
],
);
}
}

class _ButterFlyAssetVideoInList extends StatelessWidget {
const _ButterFlyAssetVideoInList(this.viewType);

final VideoViewType viewType;

@override
Widget build(BuildContext context) {
return ListView(
Expand All @@ -90,7 +162,7 @@ class _ButterFlyAssetVideoInList extends StatelessWidget {
alignment: FractionalOffset.bottomRight +
const FractionalOffset(-0.1, -0.1),
children: <Widget>[
_ButterFlyAssetVideo(),
_ButterFlyAssetVideo(viewType),
Image.asset('assets/flutter-mark-square-64.png'),
]),
],
Expand Down Expand Up @@ -150,6 +222,10 @@ class _ExampleCard extends StatelessWidget {
}

class _ButterFlyAssetVideo extends StatefulWidget {
const _ButterFlyAssetVideo(this.viewType);

final VideoViewType viewType;

@override
_ButterFlyAssetVideoState createState() => _ButterFlyAssetVideoState();
}
Expand All @@ -160,7 +236,10 @@ class _ButterFlyAssetVideoState extends State<_ButterFlyAssetVideo> {
@override
void initState() {
super.initState();
_controller = VideoPlayerController.asset('assets/Butterfly-209.mp4');
_controller = VideoPlayerController.asset(
'assets/Butterfly-209.mp4',
viewType: widget.viewType,
);

_controller.addListener(() {
setState(() {});
Expand Down Expand Up @@ -206,6 +285,10 @@ class _ButterFlyAssetVideoState extends State<_ButterFlyAssetVideo> {
}

class _BumbleBeeRemoteVideo extends StatefulWidget {
const _BumbleBeeRemoteVideo(this.viewType);

final VideoViewType viewType;

@override
_BumbleBeeRemoteVideoState createState() => _BumbleBeeRemoteVideoState();
}
Expand All @@ -228,6 +311,7 @@ class _BumbleBeeRemoteVideoState extends State<_BumbleBeeRemoteVideo> {
'https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4'),
closedCaptionFile: _loadCaptions(),
videoPlayerOptions: VideoPlayerOptions(mixWithOthers: true),
viewType: widget.viewType,
);

_controller.addListener(() {
Expand Down
Loading