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_platform_interface] Platform view support #8453

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,67 +44,81 @@ abstract class VideoPlayerPlatform extends PlatformInterface {
}

/// Clears one video.
Future<void> dispose(int textureId) {
Future<void> dispose(int playerId) {
Copy link
Contributor

Choose a reason for hiding this comment

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

is playerId used for both textureId (for texture based implementation) and playerId (for platform view implementation)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, playerId is used for both. The goal is to stop using the texture ID in the app-facing package, and rely only on the player ID (though initially the player ID would be the same as the texture ID for texture-based players, it would just not be explicitly revealed).

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<int?> 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<int?> createWithOptions(VideoCreationOptions options) {
return create(options.dataSource);
}

/// Returns a Stream of [VideoEventType]s.
Stream<VideoEvent> videoEventsFor(int textureId) {
Stream<VideoEvent> videoEventsFor(int playerId) {
throw UnimplementedError('videoEventsFor() has not been implemented.');
}

/// Sets the looping attribute of the video.
Future<void> setLooping(int textureId, bool looping) {
Future<void> setLooping(int playerId, bool looping) {
throw UnimplementedError('setLooping() has not been implemented.');
}

/// Starts the video playback.
Future<void> play(int textureId) {
Future<void> play(int playerId) {
throw UnimplementedError('play() has not been implemented.');
}

/// Stops the video playback.
Future<void> pause(int textureId) {
Future<void> pause(int playerId) {
throw UnimplementedError('pause() has not been implemented.');
}

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

/// Sets the video position to a [Duration] from the start.
Future<void> seekTo(int textureId, Duration position) {
Future<void> 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<void> setPlaybackSpeed(int textureId, double speed) {
Future<void> setPlaybackSpeed(int playerId, double speed) {
throw UnimplementedError('setPlaybackSpeed() has not been implemented.');
}

/// Gets the video position as [Duration] from the start.
Future<Duration> getPosition(int textureId) {
Future<Duration> 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<void> setMixWithOthers(bool mixWithOthers) {
throw UnimplementedError('setMixWithOthers() has not been implemented.');
}

/// Sets additional options on web
Future<void> setWebOptions(int textureId, VideoPlayerWebOptions options) {
/// Sets additional options on web.
Future<void> setWebOptions(int playerId, VideoPlayerWebOptions options) {
throw UnimplementedError('setWebOptions() has not been implemented.');
}
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading