Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[video_player] add support for content-uri based videos #4330

Merged
merged 4 commits into from
Sep 9, 2021
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
4 changes: 4 additions & 0 deletions packages/video_player/video_player/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.2.0

* Add `contentUri` based VideoPlayerController.

## 2.1.15

* Ensured seekTo isn't called before video player is initialized. Fixes [#89259](https://github.com/flutter/flutter/issues/89259).
Expand Down
21 changes: 21 additions & 0 deletions packages/video_player/video_player/lib/video_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,21 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
httpHeaders = const {},
super(VideoPlayerValue(duration: Duration.zero));

/// Constructs a [VideoPlayerController] playing a video from a contentUri.
///
/// This will load the video from the input content-URI.
/// This is supported on Android only.
VideoPlayerController.contentUri(Uri contentUri,
{this.closedCaptionFile, this.videoPlayerOptions})
: assert(defaultTargetPlatform == TargetPlatform.android,
'VideoPlayerController.contentUri is only supported on Android.'),
dataSource = contentUri.toString(),
dataSourceType = DataSourceType.contentUri,
package = null,
formatHint = null,
httpHeaders = const {},
super(VideoPlayerValue(duration: Duration.zero));

/// The URI to the video file. This will be in different formats depending on
/// the [DataSourceType] of the original video.
final String dataSource;
Expand Down Expand Up @@ -298,6 +313,12 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
uri: dataSource,
);
break;
case DataSourceType.contentUri:
dataSourceDescription = DataSource(
sourceType: DataSourceType.contentUri,
uri: dataSource,
);
break;
}

if (videoPlayerOptions?.mixWithOthers != null) {
Expand Down
4 changes: 2 additions & 2 deletions packages/video_player/video_player/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Flutter plugin for displaying inline video with other Flutter
widgets on Android, iOS, and web.
repository: https://github.com/flutter/plugins/tree/master/packages/video_player/video_player
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22
version: 2.1.15
version: 2.2.0

environment:
sdk: ">=2.12.0 <3.0.0"
Expand All @@ -24,7 +24,7 @@ dependencies:
flutter:
sdk: flutter
meta: ^1.3.0
video_player_platform_interface: ^4.1.0
video_player_platform_interface: ^4.2.0
# The design on https://flutter.dev/go/federated-plugins was to leave
# this constraint as "any". We cannot do it right now as it fails pub publish
# validation, so we set a ^ constraint. The exact value doesn't matter since
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,15 @@ void main() {
});
});

test('contentUri', () async {
final VideoPlayerController controller =
VideoPlayerController.contentUri(Uri.parse('content://video'));
await controller.initialize();

expect(fakeVideoPlayerPlatform.dataSourceDescriptions[0].uri,
'content://video');
});

test('dispose', () async {
final VideoPlayerController controller = VideoPlayerController.network(
'https://127.0.0.1',
Expand Down
4 changes: 4 additions & 0 deletions packages/video_player/video_player_web/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.0.4

* Adopt `video_player_platform_interface` 4.2 and opt out of `contentUri` data source.

## 2.0.3

* Add `implements` to pubspec.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ void main() {
throwsUnimplementedError);
});

testWidgets('cannot create from content URI', (WidgetTester tester) async {
expect(
VideoPlayerPlatform.instance.create(
DataSource(
sourceType: DataSourceType.contentUri,
uri: 'content://video',
),
),
throwsUnimplementedError);
});

testWidgets('can dispose', (WidgetTester tester) async {
expect(VideoPlayerPlatform.instance.dispose(await textureId), completes);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ class VideoPlayerPlugin extends VideoPlayerPlatform {
case DataSourceType.file:
return Future.error(UnimplementedError(
'web implementation of video_player cannot play local files'));
case DataSourceType.contentUri:
return Future.error(UnimplementedError(
'web implementation of video_player cannot play content uri'));
}

final _VideoPlayer player = _VideoPlayer(
Expand Down
4 changes: 2 additions & 2 deletions packages/video_player/video_player_web/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: video_player_web
description: Web platform implementation of video_player.
repository: https://github.com/flutter/plugins/tree/master/packages/video_player/video_player_web
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22
version: 2.0.3
version: 2.0.4

environment:
sdk: ">=2.12.0 <3.0.0"
Expand All @@ -22,7 +22,7 @@ dependencies:
flutter_web_plugins:
sdk: flutter
meta: ^1.3.0
video_player_platform_interface: ^4.0.0
video_player_platform_interface: ^4.2.0

dev_dependencies:
flutter_test:
Expand Down