Skip to content

Commit 10950e3

Browse files
jmagmanamantoux
authored andcommitted
[video_player] add support for content-uri based videos (flutter#4330)
1 parent a05250c commit 10950e3

File tree

8 files changed

+57
-17
lines changed

8 files changed

+57
-17
lines changed

packages/video_player/video_player/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.2.0
2+
3+
* Add `contentUri` based VideoPlayerController.
4+
15
## 2.1.15
26

37
* Ensured seekTo isn't called before video player is initialized. Fixes [#89259](https://github.com/flutter/flutter/issues/89259).

packages/video_player/video_player/lib/video_player.dart

+21
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,21 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
228228
httpHeaders = const {},
229229
super(VideoPlayerValue(duration: Duration.zero));
230230

231+
/// Constructs a [VideoPlayerController] playing a video from a contentUri.
232+
///
233+
/// This will load the video from the input content-URI.
234+
/// This is supported on Android only.
235+
VideoPlayerController.contentUri(Uri contentUri,
236+
{this.closedCaptionFile, this.videoPlayerOptions})
237+
: assert(defaultTargetPlatform == TargetPlatform.android,
238+
'VideoPlayerController.contentUri is only supported on Android.'),
239+
dataSource = contentUri.toString(),
240+
dataSourceType = DataSourceType.contentUri,
241+
package = null,
242+
formatHint = null,
243+
httpHeaders = const {},
244+
super(VideoPlayerValue(duration: Duration.zero));
245+
231246
/// The URI to the video file. This will be in different formats depending on
232247
/// the [DataSourceType] of the original video.
233248
final String dataSource;
@@ -304,6 +319,12 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
304319
uri: dataSource,
305320
);
306321
break;
322+
case DataSourceType.contentUri:
323+
dataSourceDescription = DataSource(
324+
sourceType: DataSourceType.contentUri,
325+
uri: dataSource,
326+
);
327+
break;
307328
}
308329

309330
if (videoPlayerOptions?.mixWithOthers != null) {

packages/video_player/video_player/pubspec.yaml

+3-11
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: Flutter plugin for displaying inline video with other Flutter
33
widgets on Android, iOS, and web.
44
repository: https://github.com/flutter/plugins/tree/master/packages/video_player/video_player
55
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22
6-
version: 2.1.15
6+
version: 2.2.0
77

88
environment:
99
sdk: ">=2.12.0 <3.0.0"
@@ -24,22 +24,14 @@ dependencies:
2424
flutter:
2525
sdk: flutter
2626
meta: ^1.3.0
27-
video_player_platform_interface:
28-
git:
29-
url: https://github.com/amantoux/plugins
30-
ref: rotation
31-
path: packages/video_player/video_player_platform_interface
27+
video_player_platform_interface: ^4.2.0
3228
# The design on https://flutter.dev/go/federated-plugins was to leave
3329
# this constraint as "any". We cannot do it right now as it fails pub publish
3430
# validation, so we set a ^ constraint. The exact value doesn't matter since
3531
# the constraints on the interface pins it.
3632
# TODO(amirh): Revisit this (either update this part in the design or the pub tool).
3733
# https://github.com/flutter/flutter/issues/46264
38-
video_player_web:
39-
git:
40-
url: https://github.com/amantoux/plugins
41-
ref: rotation
42-
path: packages/video_player/video_player_web
34+
video_player_web: ^2.0.0
4335

4436
dev_dependencies:
4537
flutter_test:

packages/video_player/video_player/test/video_player_test.dart

+9
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,15 @@ void main() {
284284
});
285285
});
286286

287+
test('contentUri', () async {
288+
final VideoPlayerController controller =
289+
VideoPlayerController.contentUri(Uri.parse('content://video'));
290+
await controller.initialize();
291+
292+
expect(fakeVideoPlayerPlatform.dataSourceDescriptions[0].uri,
293+
'content://video');
294+
});
295+
287296
test('dispose', () async {
288297
final VideoPlayerController controller = VideoPlayerController.network(
289298
'https://127.0.0.1',

packages/video_player/video_player_web/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.0.4
2+
3+
* Adopt `video_player_platform_interface` 4.2 and opt out of `contentUri` data source.
4+
15
## 2.0.3
26

37
* Add `implements` to pubspec.

packages/video_player/video_player_web/example/integration_test/video_player_web_test.dart

+11
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,17 @@ void main() {
6868
throwsUnimplementedError);
6969
});
7070

71+
testWidgets('cannot create from content URI', (WidgetTester tester) async {
72+
expect(
73+
VideoPlayerPlatform.instance.create(
74+
DataSource(
75+
sourceType: DataSourceType.contentUri,
76+
uri: 'content://video',
77+
),
78+
),
79+
throwsUnimplementedError);
80+
});
81+
7182
testWidgets('can dispose', (WidgetTester tester) async {
7283
expect(VideoPlayerPlatform.instance.dispose(await textureId), completes);
7384
});

packages/video_player/video_player_web/lib/video_player_web.dart

+3
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ class VideoPlayerPlugin extends VideoPlayerPlatform {
8888
case DataSourceType.file:
8989
return Future.error(UnimplementedError(
9090
'web implementation of video_player cannot play local files'));
91+
case DataSourceType.contentUri:
92+
return Future.error(UnimplementedError(
93+
'web implementation of video_player cannot play content uri'));
9194
}
9295

9396
final _VideoPlayer player = _VideoPlayer(

packages/video_player/video_player_web/pubspec.yaml

+2-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: video_player_web
22
description: Web platform implementation of video_player.
33
repository: https://github.com/flutter/plugins/tree/master/packages/video_player/video_player_web
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22
5-
version: 2.0.3
5+
version: 2.0.4
66

77
environment:
88
sdk: ">=2.12.0 <3.0.0"
@@ -22,11 +22,7 @@ dependencies:
2222
flutter_web_plugins:
2323
sdk: flutter
2424
meta: ^1.3.0
25-
video_player_platform_interface:
26-
git:
27-
url: https://github.com/amantoux/plugins
28-
ref: rotation
29-
path: packages/video_player/video_player_platform_interface
25+
video_player_platform_interface: ^4.2.0
3026

3127
dev_dependencies:
3228
flutter_test:

0 commit comments

Comments
 (0)