From 7137f4aaf4bced2a9599f31d85e6186f65d7138c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Jakubowski?= Date: Fri, 17 Jan 2025 10:45:12 +0100 Subject: [PATCH 1/6] Allow choosing view type when creating a video player --- .../lib/video_player_platform_interface.dart | 54 ++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/packages/video_player/video_player_platform_interface/lib/video_player_platform_interface.dart b/packages/video_player/video_player_platform_interface/lib/video_player_platform_interface.dart index d169c5f16d4..5b3bd427fbf 100644 --- a/packages/video_player/video_player_platform_interface/lib/video_player_platform_interface.dart +++ b/packages/video_player/video_player_platform_interface/lib/video_player_platform_interface.dart @@ -48,11 +48,18 @@ abstract class VideoPlayerPlatform extends PlatformInterface { throw UnimplementedError('dispose() has not been implemented.'); } - /// Creates an instance of a video player and returns its textureId. + /// Creates an instance of a video player and returns its playerId. + @Deprecated('Use createWithOptions() instead.') Future create(DataSource dataSource) { throw UnimplementedError('create() has not been implemented.'); } + /// Creates an instance of a video player based on creation options + /// and returns its playerId. + Future createWithOptions(VideoCreationOptions options) { + return create(options.dataSource); + } + /// Returns a Stream of [VideoEventType]s. Stream videoEventsFor(int textureId) { throw UnimplementedError('videoEventsFor() has not been implemented.'); @@ -93,11 +100,19 @@ abstract class VideoPlayerPlatform extends PlatformInterface { throw UnimplementedError('getPosition() has not been implemented.'); } + // TODO(FirentisTFW): Rename textureId to playerId everywhere. /// Returns a widget displaying the video with a given textureID. + @Deprecated('Use buildViewWithOptions() instead.') Widget buildView(int textureId) { throw UnimplementedError('buildView() has not been implemented.'); } + /// Returns a widget displaying the video based on given options. + Widget buildViewWithOptions(VideoViewOptions options) { + // Default implementation for backwards compatibility. + return buildView(options.playerId); + } + /// Sets the audio mode to mix with other sources Future setMixWithOthers(bool mixWithOthers) { throw UnimplementedError('setMixWithOthers() has not been implemented.'); @@ -198,6 +213,15 @@ enum VideoFormat { other, } +/// The type of video view to be used. +enum VideoViewType { + /// Texture will be used to render video. + textureView, + + /// Platform view will be used to render video. + platformView, +} + /// Event emitted from the platform implementation. @immutable class VideoEvent { @@ -476,3 +500,31 @@ class VideoPlayerWebOptionsControls { return controlsList.join(' '); } } + +/// [VideoViewOptions] contains configuration options for a video view. +@immutable +class VideoViewOptions { + /// Constructs an instance of [VideoViewOptions]. + const VideoViewOptions({ + required this.playerId, + }); + + /// The identifier of the video player. + final int playerId; +} + +/// [VideoCreationOptions] contains creation options for a video player. +@immutable +class VideoCreationOptions { + /// Constructs an instance of [VideoCreationOptions]. + const VideoCreationOptions({ + required this.dataSource, + required this.viewType, + }); + + /// The data source used to create the player. + final DataSource dataSource; + + /// The type of view to be used for displaying the video player + final VideoViewType viewType; +} From 5f12fb74fb1be6c9ff530b3f0391b3e1f510a589 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Jakubowski?= Date: Fri, 17 Jan 2025 10:46:05 +0100 Subject: [PATCH 2/6] Bump version to 6.3.0 --- .../video_player/video_player_platform_interface/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/video_player/video_player_platform_interface/pubspec.yaml b/packages/video_player/video_player_platform_interface/pubspec.yaml index 6a0f1e65c21..66b12850703 100644 --- a/packages/video_player/video_player_platform_interface/pubspec.yaml +++ b/packages/video_player/video_player_platform_interface/pubspec.yaml @@ -4,7 +4,7 @@ repository: https://github.com/flutter/packages/tree/main/packages/video_player/ issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22 # NOTE: We strongly prefer non-breaking changes, even at the expense of a # less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes -version: 6.2.3 +version: 6.3.0 environment: sdk: ^3.4.0 From 44efbea5c26378a19f0d464394e45031cced124a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Jakubowski?= Date: Fri, 17 Jan 2025 10:46:13 +0100 Subject: [PATCH 3/6] Update changelog --- .../video_player/video_player_platform_interface/CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/video_player/video_player_platform_interface/CHANGELOG.md b/packages/video_player/video_player_platform_interface/CHANGELOG.md index 3c1e70fec40..5e8f06df267 100644 --- a/packages/video_player/video_player_platform_interface/CHANGELOG.md +++ b/packages/video_player/video_player_platform_interface/CHANGELOG.md @@ -1,5 +1,6 @@ -## NEXT +## 6.3.0 +* Adds support for platform views as an optional way of displaying a video. * Updates minimum supported SDK version to Flutter 3.22/Dart 3.4. ## 6.2.3 From e8ecc5c7b964cca4c0a7dcc421db3ac2bcc99b1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Jakubowski?= Date: Mon, 20 Jan 2025 08:52:01 +0100 Subject: [PATCH 4/6] Rename textureId to playerId in platform interface methods --- .../lib/video_player_platform_interface.dart | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/packages/video_player/video_player_platform_interface/lib/video_player_platform_interface.dart b/packages/video_player/video_player_platform_interface/lib/video_player_platform_interface.dart index 5b3bd427fbf..bf8ef81777a 100644 --- a/packages/video_player/video_player_platform_interface/lib/video_player_platform_interface.dart +++ b/packages/video_player/video_player_platform_interface/lib/video_player_platform_interface.dart @@ -44,7 +44,7 @@ abstract class VideoPlayerPlatform extends PlatformInterface { } /// Clears one video. - Future dispose(int textureId) { + Future dispose(int playerId) { throw UnimplementedError('dispose() has not been implemented.'); } @@ -61,49 +61,48 @@ abstract class VideoPlayerPlatform extends PlatformInterface { } /// Returns a Stream of [VideoEventType]s. - Stream videoEventsFor(int textureId) { + Stream videoEventsFor(int playerId) { throw UnimplementedError('videoEventsFor() has not been implemented.'); } /// Sets the looping attribute of the video. - Future setLooping(int textureId, bool looping) { + Future setLooping(int playerId, bool looping) { throw UnimplementedError('setLooping() has not been implemented.'); } /// Starts the video playback. - Future play(int textureId) { + Future play(int playerId) { throw UnimplementedError('play() has not been implemented.'); } /// Stops the video playback. - Future pause(int textureId) { + Future pause(int playerId) { throw UnimplementedError('pause() has not been implemented.'); } /// Sets the volume to a range between 0.0 and 1.0. - Future setVolume(int textureId, double volume) { + Future setVolume(int playerId, double volume) { throw UnimplementedError('setVolume() has not been implemented.'); } /// Sets the video position to a [Duration] from the start. - Future seekTo(int textureId, Duration position) { + Future seekTo(int playerId, Duration position) { throw UnimplementedError('seekTo() has not been implemented.'); } /// Sets the playback speed to a [speed] value indicating the playback rate. - Future setPlaybackSpeed(int textureId, double speed) { + Future setPlaybackSpeed(int playerId, double speed) { throw UnimplementedError('setPlaybackSpeed() has not been implemented.'); } /// Gets the video position as [Duration] from the start. - Future getPosition(int textureId) { + Future getPosition(int playerId) { throw UnimplementedError('getPosition() has not been implemented.'); } - // TODO(FirentisTFW): Rename textureId to playerId everywhere. - /// Returns a widget displaying the video with a given textureID. + /// Returns a widget displaying the video with a given playerID. @Deprecated('Use buildViewWithOptions() instead.') - Widget buildView(int textureId) { + Widget buildView(int playerId) { throw UnimplementedError('buildView() has not been implemented.'); } @@ -119,7 +118,7 @@ abstract class VideoPlayerPlatform extends PlatformInterface { } /// Sets additional options on web - Future setWebOptions(int textureId, VideoPlayerWebOptions options) { + Future setWebOptions(int playerId, VideoPlayerWebOptions options) { throw UnimplementedError('setWebOptions() has not been implemented.'); } } From dd8ff5b93781dfd6ee7d8f0563aa6e4fd9c33714 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Jakubowski?= Date: Mon, 20 Jan 2025 09:19:38 +0100 Subject: [PATCH 5/6] Add ignores for renaming method parameters to platform implementations --- packages/video_player/video_player/test/video_player_test.dart | 3 +++ .../video_player_android/lib/src/android_video_player.dart | 3 +++ .../lib/src/avfoundation_video_player.dart | 3 +++ .../video_player/video_player_web/lib/video_player_web.dart | 3 +++ 4 files changed, 12 insertions(+) diff --git a/packages/video_player/video_player/test/video_player_test.dart b/packages/video_player/video_player/test/video_player_test.dart index f6eef244811..4db06eae690 100644 --- a/packages/video_player/video_player/test/video_player_test.dart +++ b/packages/video_player/video_player/test/video_player_test.dart @@ -14,6 +14,9 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:video_player/video_player.dart'; import 'package:video_player_platform_interface/video_player_platform_interface.dart'; +// TODO(FirentisTFW): Remove the ignore and rename parameters when adding support for platform views. +// ignore_for_file: avoid_renaming_method_parameters + const String _localhost = 'https://127.0.0.1'; final Uri _localhostUri = Uri.parse(_localhost); diff --git a/packages/video_player/video_player_android/lib/src/android_video_player.dart b/packages/video_player/video_player_android/lib/src/android_video_player.dart index 45665631d93..42b509729f9 100644 --- a/packages/video_player/video_player_android/lib/src/android_video_player.dart +++ b/packages/video_player/video_player_android/lib/src/android_video_player.dart @@ -10,6 +10,9 @@ import 'package:video_player_platform_interface/video_player_platform_interface. import 'messages.g.dart'; +// TODO(FirentisTFW): Remove the ignore and rename parameters when adding support for platform views. +// ignore_for_file: avoid_renaming_method_parameters + /// An Android implementation of [VideoPlayerPlatform] that uses the /// Pigeon-generated [VideoPlayerApi]. class AndroidVideoPlayer extends VideoPlayerPlatform { diff --git a/packages/video_player/video_player_avfoundation/lib/src/avfoundation_video_player.dart b/packages/video_player/video_player_avfoundation/lib/src/avfoundation_video_player.dart index ace8f749a6b..584d4730731 100644 --- a/packages/video_player/video_player_avfoundation/lib/src/avfoundation_video_player.dart +++ b/packages/video_player/video_player_avfoundation/lib/src/avfoundation_video_player.dart @@ -10,6 +10,9 @@ import 'package:video_player_platform_interface/video_player_platform_interface. import 'messages.g.dart'; +// TODO(FirentisTFW): Remove the ignore and rename parameters when adding support for platform views. +// ignore_for_file: avoid_renaming_method_parameters + /// An iOS implementation of [VideoPlayerPlatform] that uses the /// Pigeon-generated [VideoPlayerApi]. class AVFoundationVideoPlayer extends VideoPlayerPlatform { diff --git a/packages/video_player/video_player_web/lib/video_player_web.dart b/packages/video_player/video_player_web/lib/video_player_web.dart index 8f5c0265e96..45a7285bb56 100644 --- a/packages/video_player/video_player_web/lib/video_player_web.dart +++ b/packages/video_player/video_player_web/lib/video_player_web.dart @@ -12,6 +12,9 @@ import 'package:web/web.dart' as web; import 'src/video_player.dart'; +// TODO(FirentisTFW): Remove the ignore and rename parameters when adding support for platform views. +// ignore_for_file: avoid_renaming_method_parameters + /// The web implementation of [VideoPlayerPlatform]. /// /// This class implements the `package:video_player` functionality for the web. From ca5dfb532291efef6478fce7f46859028a8602ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Jakubowski?= Date: Mon, 20 Jan 2025 10:28:49 +0100 Subject: [PATCH 6/6] Update dartdocs for consistency --- .../lib/video_player_platform_interface.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/video_player/video_player_platform_interface/lib/video_player_platform_interface.dart b/packages/video_player/video_player_platform_interface/lib/video_player_platform_interface.dart index bf8ef81777a..13c9cf55aa7 100644 --- a/packages/video_player/video_player_platform_interface/lib/video_player_platform_interface.dart +++ b/packages/video_player/video_player_platform_interface/lib/video_player_platform_interface.dart @@ -100,7 +100,7 @@ abstract class VideoPlayerPlatform extends PlatformInterface { throw UnimplementedError('getPosition() has not been implemented.'); } - /// Returns a widget displaying the video with a given playerID. + /// Returns a widget displaying the video with a given playerId. @Deprecated('Use buildViewWithOptions() instead.') Widget buildView(int playerId) { throw UnimplementedError('buildView() has not been implemented.'); @@ -112,12 +112,12 @@ abstract class VideoPlayerPlatform extends PlatformInterface { return buildView(options.playerId); } - /// Sets the audio mode to mix with other sources + /// Sets the audio mode to mix with other sources. Future setMixWithOthers(bool mixWithOthers) { throw UnimplementedError('setMixWithOthers() has not been implemented.'); } - /// Sets additional options on web + /// Sets additional options on web. Future setWebOptions(int playerId, VideoPlayerWebOptions options) { throw UnimplementedError('setWebOptions() has not been implemented.'); }