Skip to content

Commit 941c89f

Browse files
jmagmanfotiDim
authored andcommitted
[video_player] add support for content-uri based videos (flutter#4330)
1 parent 432034f commit 941c89f

File tree

8 files changed

+56
-4
lines changed

8 files changed

+56
-4
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
@@ -222,6 +222,21 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
222222
httpHeaders = const {},
223223
super(VideoPlayerValue(duration: Duration.zero));
224224

225+
/// Constructs a [VideoPlayerController] playing a video from a contentUri.
226+
///
227+
/// This will load the video from the input content-URI.
228+
/// This is supported on Android only.
229+
VideoPlayerController.contentUri(Uri contentUri,
230+
{this.closedCaptionFile, this.videoPlayerOptions})
231+
: assert(defaultTargetPlatform == TargetPlatform.android,
232+
'VideoPlayerController.contentUri is only supported on Android.'),
233+
dataSource = contentUri.toString(),
234+
dataSourceType = DataSourceType.contentUri,
235+
package = null,
236+
formatHint = null,
237+
httpHeaders = const {},
238+
super(VideoPlayerValue(duration: Duration.zero));
239+
225240
/// The URI to the video file. This will be in different formats depending on
226241
/// the [DataSourceType] of the original video.
227242
final String dataSource;
@@ -298,6 +313,12 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
298313
uri: dataSource,
299314
);
300315
break;
316+
case DataSourceType.contentUri:
317+
dataSourceDescription = DataSource(
318+
sourceType: DataSourceType.contentUri,
319+
uri: dataSource,
320+
);
321+
break;
301322
}
302323

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

packages/video_player/video_player/pubspec.yaml

+2-2
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,7 +24,7 @@ dependencies:
2424
flutter:
2525
sdk: flutter
2626
meta: ^1.3.0
27-
video_player_platform_interface: ^4.1.0
27+
video_player_platform_interface: ^4.2.0
2828
# The design on https://flutter.dev/go/federated-plugins was to leave
2929
# this constraint as "any". We cannot do it right now as it fails pub publish
3030
# validation, so we set a ^ constraint. The exact value doesn't matter since

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-2
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,7 +22,7 @@ dependencies:
2222
flutter_web_plugins:
2323
sdk: flutter
2424
meta: ^1.3.0
25-
video_player_platform_interface: ^4.0.0
25+
video_player_platform_interface: ^4.2.0
2626

2727
dev_dependencies:
2828
flutter_test:

0 commit comments

Comments
 (0)