Skip to content

Commit 2165b5c

Browse files
authored
[video_player_platform_interface] Platform view support (#8453)
This PR is a subset of #8237 - it only adds platform interface changes. Partially resolves [86613](flutter/flutter#86613).
1 parent 15d1e92 commit 2165b5c

File tree

7 files changed

+81
-17
lines changed

7 files changed

+81
-17
lines changed

packages/video_player/video_player/test/video_player_test.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import 'package:flutter_test/flutter_test.dart';
1414
import 'package:video_player/video_player.dart';
1515
import 'package:video_player_platform_interface/video_player_platform_interface.dart';
1616

17+
// TODO(FirentisTFW): Remove the ignore and rename parameters when adding support for platform views.
18+
// ignore_for_file: avoid_renaming_method_parameters
19+
1720
const String _localhost = 'https://127.0.0.1';
1821
final Uri _localhostUri = Uri.parse(_localhost);
1922

packages/video_player/video_player_android/lib/src/android_video_player.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import 'package:video_player_platform_interface/video_player_platform_interface.
1010

1111
import 'messages.g.dart';
1212

13+
// TODO(FirentisTFW): Remove the ignore and rename parameters when adding support for platform views.
14+
// ignore_for_file: avoid_renaming_method_parameters
15+
1316
/// An Android implementation of [VideoPlayerPlatform] that uses the
1417
/// Pigeon-generated [VideoPlayerApi].
1518
class AndroidVideoPlayer extends VideoPlayerPlatform {

packages/video_player/video_player_avfoundation/lib/src/avfoundation_video_player.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import 'package:video_player_platform_interface/video_player_platform_interface.
1010

1111
import 'messages.g.dart';
1212

13+
// TODO(FirentisTFW): Remove the ignore and rename parameters when adding support for platform views.
14+
// ignore_for_file: avoid_renaming_method_parameters
15+
1316
/// An iOS implementation of [VideoPlayerPlatform] that uses the
1417
/// Pigeon-generated [VideoPlayerApi].
1518
class AVFoundationVideoPlayer extends VideoPlayerPlatform {

packages/video_player/video_player_platform_interface/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
## NEXT
1+
## 6.3.0
22

3+
* Adds support for platform views as an optional way of displaying a video.
34
* Updates minimum supported SDK version to Flutter 3.22/Dart 3.4.
45

56
## 6.2.3

packages/video_player/video_player_platform_interface/lib/video_player_platform_interface.dart

Lines changed: 66 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,67 +44,81 @@ abstract class VideoPlayerPlatform extends PlatformInterface {
4444
}
4545

4646
/// Clears one video.
47-
Future<void> dispose(int textureId) {
47+
Future<void> dispose(int playerId) {
4848
throw UnimplementedError('dispose() has not been implemented.');
4949
}
5050

51-
/// Creates an instance of a video player and returns its textureId.
51+
/// Creates an instance of a video player and returns its playerId.
52+
@Deprecated('Use createWithOptions() instead.')
5253
Future<int?> create(DataSource dataSource) {
5354
throw UnimplementedError('create() has not been implemented.');
5455
}
5556

57+
/// Creates an instance of a video player based on creation options
58+
/// and returns its playerId.
59+
Future<int?> createWithOptions(VideoCreationOptions options) {
60+
return create(options.dataSource);
61+
}
62+
5663
/// Returns a Stream of [VideoEventType]s.
57-
Stream<VideoEvent> videoEventsFor(int textureId) {
64+
Stream<VideoEvent> videoEventsFor(int playerId) {
5865
throw UnimplementedError('videoEventsFor() has not been implemented.');
5966
}
6067

6168
/// Sets the looping attribute of the video.
62-
Future<void> setLooping(int textureId, bool looping) {
69+
Future<void> setLooping(int playerId, bool looping) {
6370
throw UnimplementedError('setLooping() has not been implemented.');
6471
}
6572

6673
/// Starts the video playback.
67-
Future<void> play(int textureId) {
74+
Future<void> play(int playerId) {
6875
throw UnimplementedError('play() has not been implemented.');
6976
}
7077

7178
/// Stops the video playback.
72-
Future<void> pause(int textureId) {
79+
Future<void> pause(int playerId) {
7380
throw UnimplementedError('pause() has not been implemented.');
7481
}
7582

7683
/// Sets the volume to a range between 0.0 and 1.0.
77-
Future<void> setVolume(int textureId, double volume) {
84+
Future<void> setVolume(int playerId, double volume) {
7885
throw UnimplementedError('setVolume() has not been implemented.');
7986
}
8087

8188
/// Sets the video position to a [Duration] from the start.
82-
Future<void> seekTo(int textureId, Duration position) {
89+
Future<void> seekTo(int playerId, Duration position) {
8390
throw UnimplementedError('seekTo() has not been implemented.');
8491
}
8592

8693
/// Sets the playback speed to a [speed] value indicating the playback rate.
87-
Future<void> setPlaybackSpeed(int textureId, double speed) {
94+
Future<void> setPlaybackSpeed(int playerId, double speed) {
8895
throw UnimplementedError('setPlaybackSpeed() has not been implemented.');
8996
}
9097

9198
/// Gets the video position as [Duration] from the start.
92-
Future<Duration> getPosition(int textureId) {
99+
Future<Duration> getPosition(int playerId) {
93100
throw UnimplementedError('getPosition() has not been implemented.');
94101
}
95102

96-
/// Returns a widget displaying the video with a given textureID.
97-
Widget buildView(int textureId) {
103+
/// Returns a widget displaying the video with a given playerId.
104+
@Deprecated('Use buildViewWithOptions() instead.')
105+
Widget buildView(int playerId) {
98106
throw UnimplementedError('buildView() has not been implemented.');
99107
}
100108

101-
/// Sets the audio mode to mix with other sources
109+
/// Returns a widget displaying the video based on given options.
110+
Widget buildViewWithOptions(VideoViewOptions options) {
111+
// Default implementation for backwards compatibility.
112+
return buildView(options.playerId);
113+
}
114+
115+
/// Sets the audio mode to mix with other sources.
102116
Future<void> setMixWithOthers(bool mixWithOthers) {
103117
throw UnimplementedError('setMixWithOthers() has not been implemented.');
104118
}
105119

106-
/// Sets additional options on web
107-
Future<void> setWebOptions(int textureId, VideoPlayerWebOptions options) {
120+
/// Sets additional options on web.
121+
Future<void> setWebOptions(int playerId, VideoPlayerWebOptions options) {
108122
throw UnimplementedError('setWebOptions() has not been implemented.');
109123
}
110124
}
@@ -198,6 +212,15 @@ enum VideoFormat {
198212
other,
199213
}
200214

215+
/// The type of video view to be used.
216+
enum VideoViewType {
217+
/// Texture will be used to render video.
218+
textureView,
219+
220+
/// Platform view will be used to render video.
221+
platformView,
222+
}
223+
201224
/// Event emitted from the platform implementation.
202225
@immutable
203226
class VideoEvent {
@@ -476,3 +499,31 @@ class VideoPlayerWebOptionsControls {
476499
return controlsList.join(' ');
477500
}
478501
}
502+
503+
/// [VideoViewOptions] contains configuration options for a video view.
504+
@immutable
505+
class VideoViewOptions {
506+
/// Constructs an instance of [VideoViewOptions].
507+
const VideoViewOptions({
508+
required this.playerId,
509+
});
510+
511+
/// The identifier of the video player.
512+
final int playerId;
513+
}
514+
515+
/// [VideoCreationOptions] contains creation options for a video player.
516+
@immutable
517+
class VideoCreationOptions {
518+
/// Constructs an instance of [VideoCreationOptions].
519+
const VideoCreationOptions({
520+
required this.dataSource,
521+
required this.viewType,
522+
});
523+
524+
/// The data source used to create the player.
525+
final DataSource dataSource;
526+
527+
/// The type of view to be used for displaying the video player
528+
final VideoViewType viewType;
529+
}

packages/video_player/video_player_platform_interface/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ repository: https://github.com/flutter/packages/tree/main/packages/video_player/
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22
55
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
66
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
7-
version: 6.2.3
7+
version: 6.3.0
88

99
environment:
1010
sdk: ^3.4.0

packages/video_player/video_player_web/lib/video_player_web.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ import 'package:web/web.dart' as web;
1212

1313
import 'src/video_player.dart';
1414

15+
// TODO(FirentisTFW): Remove the ignore and rename parameters when adding support for platform views.
16+
// ignore_for_file: avoid_renaming_method_parameters
17+
1518
/// The web implementation of [VideoPlayerPlatform].
1619
///
1720
/// This class implements the `package:video_player` functionality for the web.

0 commit comments

Comments
 (0)