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

[video_player] Fix file URI construction #6803

Merged
merged 6 commits into from
Dec 8, 2022
Merged
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
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.4.9

* Fixes file URI construction.

## 2.4.8

* Updates code for new analysis options.
Expand Down
5 changes: 2 additions & 3 deletions packages/video_player/video_player/lib/video_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,11 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {

/// Constructs a [VideoPlayerController] playing a video from a file.
///
/// This will load the file from the file-URI given by:
/// `'file://${file.path}'`.
/// This will load the file from a file:// URI constructed from [file]'s path.
VideoPlayerController.file(File file,
{Future<ClosedCaptionFile>? closedCaptionFile, this.videoPlayerOptions})
: _closedCaptionFileFuture = closedCaptionFile,
dataSource = 'file://${file.path}',
dataSource = Uri.file(file.absolute.path).toString(),
dataSourceType = DataSourceType.file,
package = null,
formatHint = null,
Expand Down
2 changes: 1 addition & 1 deletion 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/main/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.4.8
version: 2.4.9

environment:
sdk: ">=2.14.0 <3.0.0"
Expand Down
30 changes: 22 additions & 8 deletions packages/video_player/video_player/test/video_player_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'dart:io';
import 'dart:math' as math;
import 'dart:typed_data';

import 'package:flutter/foundation.dart' show kIsWeb;
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
Expand Down Expand Up @@ -341,8 +342,21 @@ void main() {
VideoPlayerController.file(File('a.avi'));
await controller.initialize();

expect(fakeVideoPlayerPlatform.dataSources[0].uri, 'file://a.avi');
});
final String uri = fakeVideoPlayerPlatform.dataSources[0].uri!;
expect(uri.startsWith('file:///'), true, reason: 'Actual string: $uri');
expect(uri.endsWith('/a.avi'), true, reason: 'Actual string: $uri');
}, skip: kIsWeb /* Web does not support file assets. */);

test('file with special characters', () async {
final VideoPlayerController controller =
VideoPlayerController.file(File('A #1 Hit?.avi'));
await controller.initialize();

final String uri = fakeVideoPlayerPlatform.dataSources[0].uri!;
expect(uri.startsWith('file:///'), true, reason: 'Actual string: $uri');
expect(uri.endsWith('/A%20%231%20Hit%3F.avi'), true,
reason: 'Actual string: $uri');
}, skip: kIsWeb /* Web does not support file assets. */);

test('successful initialize on controller with error clears error',
() async {
Expand Down Expand Up @@ -1009,16 +1023,16 @@ void main() {
});

test('setMixWithOthers', () async {
final VideoPlayerController controller = VideoPlayerController.file(
File(''),
final VideoPlayerController controller = VideoPlayerController.network(
'https://127.0.0.1',
videoPlayerOptions: VideoPlayerOptions(mixWithOthers: true));
await controller.initialize();
expect(controller.videoPlayerOptions!.mixWithOthers, true);
});

test('true allowBackgroundPlayback continues playback', () async {
final VideoPlayerController controller = VideoPlayerController.file(
File(''),
final VideoPlayerController controller = VideoPlayerController.network(
'https://127.0.0.1',
videoPlayerOptions: VideoPlayerOptions(
allowBackgroundPlayback: true,
),
Expand All @@ -1032,8 +1046,8 @@ void main() {
});

test('false allowBackgroundPlayback pauses playback', () async {
final VideoPlayerController controller = VideoPlayerController.file(
File(''),
final VideoPlayerController controller = VideoPlayerController.network(
'https://127.0.0.1',
videoPlayerOptions: VideoPlayerOptions(),
);
await controller.initialize();
Expand Down
1 change: 1 addition & 0 deletions packages/video_player/video_player_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## NEXT

* Fixes file URI construction in example.
* Updates code for new analysis options.
* Updates code for `no_leading_underscores_for_local_identifiers` lint.
* Updates minimum Flutter version to 2.10.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class MiniController extends ValueNotifier<VideoPlayerValue> {

/// Constructs a [MiniController] playing a video from obtained from a file.
MiniController.file(File file)
: dataSource = 'file://${file.path}',
: dataSource = Uri.file(file.absolute.path).toString(),
dataSourceType = DataSourceType.file,
package = null,
super(VideoPlayerValue(duration: Duration.zero));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## NEXT

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

## 2.3.6

* Fixes a bug in iOS 16 where videos from protected live streams are not shown.
* Fixes a bug in iOS 16 where videos from protected live streams are not shown.
* Updates minimum Flutter version to 2.10.
* Fixes violations of new analysis option use_named_constants.
* Fixes avoid_redundant_argument_values lint warnings and minor typos.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class MiniController extends ValueNotifier<VideoPlayerValue> {

/// Constructs a [MiniController] playing a video from obtained from a file.
MiniController.file(File file)
: dataSource = 'file://${file.path}',
: dataSource = Uri.file(file.absolute.path).toString(),
dataSourceType = DataSourceType.file,
package = null,
super(VideoPlayerValue(duration: Duration.zero));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 6.0.1

* Fixes comment describing file URI construction.

## 6.0.0

* **BREAKING CHANGE**: Removes `MethodChannelVideoPlayer`. The default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class DataSource {
/// The [sourceType] is always required.
///
/// The [uri] argument takes the form of `'https://example.com/video.mp4'` or
/// `'file://${file.path}'`.
/// `'file:///absolute/path/to/local/video.mp4`.
///
/// The [formatHint] argument can be null.
///
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/main/packages/video_player/v
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: 6.0.0
version: 6.0.1

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