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 f6eef2448119..4db06eae6901 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 45665631d932..42b509729f94 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 ace8f749a6b1..584d47307310 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_platform_interface/CHANGELOG.md b/packages/video_player/video_player_platform_interface/CHANGELOG.md index 3c1e70fec40a..5e8f06df2678 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 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 d169c5f16d45..13c9cf55aa7e 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,67 +44,81 @@ abstract class VideoPlayerPlatform extends PlatformInterface { } /// Clears one video. - Future dispose(int textureId) { + Future dispose(int playerId) { 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) { + 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.'); } - /// Returns a widget displaying the video with a given textureID. - Widget buildView(int textureId) { + /// 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.'); } - /// Sets the audio mode to mix with other sources + /// 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.'); } - /// Sets additional options on web - Future setWebOptions(int textureId, VideoPlayerWebOptions options) { + /// Sets additional options on web. + Future setWebOptions(int playerId, VideoPlayerWebOptions options) { throw UnimplementedError('setWebOptions() has not been implemented.'); } } @@ -198,6 +212,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 +499,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; +} diff --git a/packages/video_player/video_player_platform_interface/pubspec.yaml b/packages/video_player/video_player_platform_interface/pubspec.yaml index 6a0f1e65c210..66b12850703a 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 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 8f5c0265e965..45a7285bb56b 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.