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 2 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