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

Commit f31a438

Browse files
[video_player] Fix file URI construction (#6803)
* Fix bug in file constructor * Fix comment in interface package * Fix minicontroller for examples/tests/ * Version bumps * Skip file tests on web * Don't use file source in non-file tests, since web doesn't support it
1 parent 929c9a6 commit f31a438

File tree

11 files changed

+40
-17
lines changed

11 files changed

+40
-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.4.9
2+
3+
* Fixes file URI construction.
4+
15
## 2.4.8
26

37
* Updates code for new analysis options.

packages/video_player/video_player/lib/video_player.dart

+2-3
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,11 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
245245

246246
/// Constructs a [VideoPlayerController] playing a video from a file.
247247
///
248-
/// This will load the file from the file-URI given by:
249-
/// `'file://${file.path}'`.
248+
/// This will load the file from a file:// URI constructed from [file]'s path.
250249
VideoPlayerController.file(File file,
251250
{Future<ClosedCaptionFile>? closedCaptionFile, this.videoPlayerOptions})
252251
: _closedCaptionFileFuture = closedCaptionFile,
253-
dataSource = 'file://${file.path}',
252+
dataSource = Uri.file(file.absolute.path).toString(),
254253
dataSourceType = DataSourceType.file,
255254
package = null,
256255
formatHint = null,

packages/video_player/video_player/pubspec.yaml

+1-1
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/main/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.4.8
6+
version: 2.4.9
77

88
environment:
99
sdk: ">=2.14.0 <3.0.0"

packages/video_player/video_player/test/video_player_test.dart

+22-8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'dart:io';
77
import 'dart:math' as math;
88
import 'dart:typed_data';
99

10+
import 'package:flutter/foundation.dart' show kIsWeb;
1011
import 'package:flutter/material.dart';
1112
import 'package:flutter/services.dart';
1213
import 'package:flutter_test/flutter_test.dart';
@@ -341,8 +342,21 @@ void main() {
341342
VideoPlayerController.file(File('a.avi'));
342343
await controller.initialize();
343344

344-
expect(fakeVideoPlayerPlatform.dataSources[0].uri, 'file://a.avi');
345-
});
345+
final String uri = fakeVideoPlayerPlatform.dataSources[0].uri!;
346+
expect(uri.startsWith('file:///'), true, reason: 'Actual string: $uri');
347+
expect(uri.endsWith('/a.avi'), true, reason: 'Actual string: $uri');
348+
}, skip: kIsWeb /* Web does not support file assets. */);
349+
350+
test('file with special characters', () async {
351+
final VideoPlayerController controller =
352+
VideoPlayerController.file(File('A #1 Hit?.avi'));
353+
await controller.initialize();
354+
355+
final String uri = fakeVideoPlayerPlatform.dataSources[0].uri!;
356+
expect(uri.startsWith('file:///'), true, reason: 'Actual string: $uri');
357+
expect(uri.endsWith('/A%20%231%20Hit%3F.avi'), true,
358+
reason: 'Actual string: $uri');
359+
}, skip: kIsWeb /* Web does not support file assets. */);
346360

347361
test('successful initialize on controller with error clears error',
348362
() async {
@@ -1009,16 +1023,16 @@ void main() {
10091023
});
10101024

10111025
test('setMixWithOthers', () async {
1012-
final VideoPlayerController controller = VideoPlayerController.file(
1013-
File(''),
1026+
final VideoPlayerController controller = VideoPlayerController.network(
1027+
'https://127.0.0.1',
10141028
videoPlayerOptions: VideoPlayerOptions(mixWithOthers: true));
10151029
await controller.initialize();
10161030
expect(controller.videoPlayerOptions!.mixWithOthers, true);
10171031
});
10181032

10191033
test('true allowBackgroundPlayback continues playback', () async {
1020-
final VideoPlayerController controller = VideoPlayerController.file(
1021-
File(''),
1034+
final VideoPlayerController controller = VideoPlayerController.network(
1035+
'https://127.0.0.1',
10221036
videoPlayerOptions: VideoPlayerOptions(
10231037
allowBackgroundPlayback: true,
10241038
),
@@ -1032,8 +1046,8 @@ void main() {
10321046
});
10331047

10341048
test('false allowBackgroundPlayback pauses playback', () async {
1035-
final VideoPlayerController controller = VideoPlayerController.file(
1036-
File(''),
1049+
final VideoPlayerController controller = VideoPlayerController.network(
1050+
'https://127.0.0.1',
10371051
videoPlayerOptions: VideoPlayerOptions(),
10381052
);
10391053
await controller.initialize();

packages/video_player/video_player_android/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## NEXT
22

3+
* Fixes file URI construction in example.
34
* Updates code for new analysis options.
45
* Updates code for `no_leading_underscores_for_local_identifiers` lint.
56
* Updates minimum Flutter version to 2.10.

packages/video_player/video_player_android/example/lib/mini_controller.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ class MiniController extends ValueNotifier<VideoPlayerValue> {
150150

151151
/// Constructs a [MiniController] playing a video from obtained from a file.
152152
MiniController.file(File file)
153-
: dataSource = 'file://${file.path}',
153+
: dataSource = Uri.file(file.absolute.path).toString(),
154154
dataSourceType = DataSourceType.file,
155155
package = null,
156156
super(VideoPlayerValue(duration: Duration.zero));

packages/video_player/video_player_avfoundation/CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## NEXT
22

3+
* Fixes file URI construction in example.
34
* Updates code for new analysis options.
45
* Adds an integration test for a bug where the aspect ratios of some HLS videos are incorrectly inverted.
56
* Removes an unnecessary override in example code.
@@ -11,7 +12,7 @@
1112

1213
## 2.3.6
1314

14-
* Fixes a bug in iOS 16 where videos from protected live streams are not shown.
15+
* Fixes a bug in iOS 16 where videos from protected live streams are not shown.
1516
* Updates minimum Flutter version to 2.10.
1617
* Fixes violations of new analysis option use_named_constants.
1718
* Fixes avoid_redundant_argument_values lint warnings and minor typos.

packages/video_player/video_player_avfoundation/example/lib/mini_controller.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ class MiniController extends ValueNotifier<VideoPlayerValue> {
150150

151151
/// Constructs a [MiniController] playing a video from obtained from a file.
152152
MiniController.file(File file)
153-
: dataSource = 'file://${file.path}',
153+
: dataSource = Uri.file(file.absolute.path).toString(),
154154
dataSourceType = DataSourceType.file,
155155
package = null,
156156
super(VideoPlayerValue(duration: Duration.zero));

packages/video_player/video_player_platform_interface/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 6.0.1
2+
3+
* Fixes comment describing file URI construction.
4+
15
## 6.0.0
26

37
* **BREAKING CHANGE**: Removes `MethodChannelVideoPlayer`. The default

packages/video_player/video_player_platform_interface/lib/video_player_platform_interface.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class DataSource {
114114
/// The [sourceType] is always required.
115115
///
116116
/// The [uri] argument takes the form of `'https://example.com/video.mp4'` or
117-
/// `'file://${file.path}'`.
117+
/// `'file:///absolute/path/to/local/video.mp4`.
118118
///
119119
/// The [formatHint] argument can be null.
120120
///

packages/video_player/video_player_platform_interface/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ repository: https://github.com/flutter/plugins/tree/main/packages/video_player/v
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22
55
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
66
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
7-
version: 6.0.0
7+
version: 6.0.1
88

99
environment:
1010
sdk: ">=2.12.0 <3.0.0"

0 commit comments

Comments
 (0)