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 (android only) #4261

Closed
wants to merge 2 commits into from
Closed
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
3 changes: 2 additions & 1 deletion packages/video_player/video_player/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## NEXT
## 2.2.0

* Add `contentUri` based VideoPlayerController.
* Updated Android lint settings.

## 2.1.14
Expand Down
6 changes: 6 additions & 0 deletions packages/video_player/video_player/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,9 @@ flutter:
- assets/flutter-mark-square-64.png
- assets/Butterfly-209.mp4
- assets/bumble_bee_captions.srt

# FOR TESTING ONLY. DO NOT MERGE.
dependency_overrides:
video_player_platform_interface:
path:
../../video_player_platform_interface
Comment on lines +36 to +41
Copy link

Choose a reason for hiding this comment

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

don't forget to delete

Copy link
Contributor

Choose a reason for hiding this comment

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

It'll be removed once the PR is split (https://github.com/flutter/flutter/wiki/Contributing-to-Plugins-and-Packages#changing-federated-plugins). It can't accidentally be left because this fails publishable.

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
10 changes: 8 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.14
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 All @@ -38,3 +38,9 @@ dev_dependencies:
sdk: flutter
pedantic: ^1.10.0
pigeon: ^0.1.21

# FOR TESTING ONLY. DO NOT MERGE.
dependency_overrides:
video_player_platform_interface:
path:
../video_player_platform_interface
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
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 4.2.0

* Add `contentUri` to `DataSourceType`.

## 4.1.0

* Add `httpHeaders` to `DataSource`
Expand Down Expand Up @@ -29,7 +33,7 @@

## 2.1.0

* Add VideoPlayerOptions with audo mix mode
* Add VideoPlayerOptions with audio mix mode

## 2.0.2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ class MethodChannelVideoPlayer extends VideoPlayerPlatform {
case DataSourceType.file:
message.uri = dataSource.uri;
break;
case DataSourceType.contentUri:
message.uri = dataSource.uri;
break;
}

TextureMessage response = await _api.create(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ enum DataSourceType {

/// The video was loaded off of the local filesystem.
file,

/// The video is available via contentUri. Android only.
contentUri,
}

/// The file format of the given video.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ repository: https://github.com/flutter/plugins/tree/master/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: 4.1.0
version: 4.2.0

environment:
sdk: ">=2.12.0 <3.0.0"
Expand Down