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

Commit

Permalink
[video_player] Add macOS implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
cbenhagen committed Mar 15, 2021
1 parent f7096d7 commit 4ed8995
Show file tree
Hide file tree
Showing 49 changed files with 3,071 additions and 75 deletions.
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.0.3

* Add macOS support.

## 2.0.2

* Fix `VideoPlayerValue` size and aspect ratio documentation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ void main() {
VideoPlayerController _controller;
tearDown(() async => _controller.dispose());

group('asset videos', () {
group('network videos', () {
setUp(() {
_controller = VideoPlayerController.asset('assets/Butterfly-209.mp4');
_controller = VideoPlayerController.network(
'https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4',
);
});

testWidgets('can be initialized', (WidgetTester tester) async {
Expand All @@ -32,81 +34,30 @@ void main() {
expect(_controller.value.position, const Duration(seconds: 0));
expect(_controller.value.isPlaying, false);
expect(_controller.value.duration,
const Duration(seconds: 7, milliseconds: 540));
const Duration(seconds: 4, milliseconds: 036));
});

testWidgets(
'reports buffering status',
(WidgetTester tester) async {
VideoPlayerController networkController = VideoPlayerController.network(
'https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4',
);
await networkController.initialize();
// Mute to allow playing without DOM interaction on Web.
// See https://developers.google.com/web/updates/2017/09/autoplay-policy-changes
await networkController.setVolume(0);
final Completer<void> started = Completer();
final Completer<void> ended = Completer();
bool startedBuffering = false;
bool endedBuffering = false;
networkController.addListener(() {
if (networkController.value.isBuffering && !startedBuffering) {
startedBuffering = true;
started.complete();
}
if (startedBuffering &&
!networkController.value.isBuffering &&
!endedBuffering) {
endedBuffering = true;
ended.complete();
}
});

await networkController.play();
await networkController.seekTo(const Duration(seconds: 5));
await tester.pumpAndSettle(_playDuration);
await networkController.pause();

expect(networkController.value.isPlaying, false);
expect(networkController.value.position,
(Duration position) => position > const Duration(seconds: 0));

await started;
expect(startedBuffering, true);
testWidgets('can be played', (WidgetTester tester) async {
await _controller.initialize();
// Mute to allow playing without DOM interaction on Web.
// See https://developers.google.com/web/updates/2017/09/autoplay-policy-changes
await _controller.setVolume(0);

await ended;
expect(endedBuffering, true);
},
skip: !(kIsWeb || defaultTargetPlatform == TargetPlatform.android),
);
await _controller.play();
await tester.pumpAndSettle(_playDuration);

testWidgets(
'can be played',
(WidgetTester tester) async {
await _controller.initialize();
// Mute to allow playing without DOM interaction on Web.
// See https://developers.google.com/web/updates/2017/09/autoplay-policy-changes
await _controller.setVolume(0);

await _controller.play();
await tester.pumpAndSettle(_playDuration);

expect(_controller.value.isPlaying, true);
expect(_controller.value.position,
(Duration position) => position > const Duration(seconds: 0));
},
);
expect(_controller.value.isPlaying, true);
expect(_controller.value.position,
(Duration position) => position > const Duration(seconds: 0));
});

testWidgets(
'can seek',
(WidgetTester tester) async {
await _controller.initialize();
testWidgets('can seek', (WidgetTester tester) async {
await _controller.initialize();

await _controller.seekTo(const Duration(seconds: 3));
await _controller.seekTo(const Duration(seconds: 3));

expect(_controller.value.position, const Duration(seconds: 3));
},
);
expect(_controller.value.position, const Duration(seconds: 3));
});

testWidgets(
'can be paused',
Expand All @@ -129,8 +80,136 @@ void main() {
},
);

testWidgets('test video player view with local asset',
(WidgetTester tester) async {
testWidgets('reports buffering status', (WidgetTester tester) async {
await _controller.initialize();
// Mute to allow playing without DOM interaction on Web.
// See https://developers.google.com/web/updates/2017/09/autoplay-policy-changes
await _controller.setVolume(0);
final Completer<void> started = Completer();
final Completer<void> ended = Completer();
bool startedBuffering = false;
bool endedBuffering = false;
_controller.addListener(
() {
if (_controller.value.isBuffering && !startedBuffering) {
startedBuffering = true;
started.complete();
}
if (startedBuffering &&
!_controller.value.isBuffering &&
!endedBuffering) {
endedBuffering = true;
ended.complete();
}
},
);

await _controller.play();
await _controller.seekTo(const Duration(seconds: 5));
await tester.pumpAndSettle(_playDuration);
await _controller.pause();

expect(_controller.value.isPlaying, false);
expect(_controller.value.position,
(Duration position) => position > const Duration(seconds: 0));

await started;
expect(startedBuffering, true);

await ended;
expect(endedBuffering, true);
});

testWidgets('can show video player', (WidgetTester tester) async {
Future<bool> started() async {
await _controller.initialize();
await _controller.play();
return true;
}

await tester.pumpWidget(Material(
elevation: 0,
child: Directionality(
textDirection: TextDirection.ltr,
child: Center(
child: FutureBuilder<bool>(
future: started(),
builder: (BuildContext context, AsyncSnapshot<bool> snapshot) {
if (snapshot.data == true) {
return AspectRatio(
aspectRatio: _controller.value.aspectRatio,
child: VideoPlayer(_controller),
);
} else {
return const Text('waiting for video to load');
}
},
),
),
),
));

await tester.pumpAndSettle(_playDuration);
expect(_controller.value.isPlaying, true);
});
});

group('asset videos', () {
setUp(() {
_controller = VideoPlayerController.asset('assets/Butterfly-209.mp4');
});

testWidgets('can be initialized', (WidgetTester tester) async {
await _controller.initialize();

expect(_controller.value.isInitialized, true);
expect(_controller.value.position, const Duration(seconds: 0));
expect(_controller.value.isPlaying, false);
expect(_controller.value.duration,
const Duration(seconds: 7, milliseconds: 540));
}, skip: (kIsWeb || defaultTargetPlatform == TargetPlatform.macOS));

testWidgets('can be played', (WidgetTester tester) async {
await _controller.initialize();
// Mute to allow playing without DOM interaction on Web.
// See https://developers.google.com/web/updates/2017/09/autoplay-policy-changes
await _controller.setVolume(0);

await _controller.play();
await tester.pumpAndSettle(_playDuration);

expect(_controller.value.isPlaying, true);
expect(_controller.value.position,
(Duration position) => position > const Duration(seconds: 0));
}, skip: (kIsWeb || defaultTargetPlatform == TargetPlatform.macOS));

testWidgets('can seek', (WidgetTester tester) async {
await _controller.initialize();

await _controller.seekTo(const Duration(seconds: 3));

expect(_controller.value.position, const Duration(seconds: 3));
}, skip: (kIsWeb || defaultTargetPlatform == TargetPlatform.macOS));

testWidgets('can be paused', (WidgetTester tester) async {
await _controller.initialize();
// Mute to allow playing without DOM interaction on Web.
// See https://developers.google.com/web/updates/2017/09/autoplay-policy-changes
await _controller.setVolume(0);

// Play for a second, then pause, and then wait a second.
await _controller.play();
await tester.pumpAndSettle(_playDuration);
await _controller.pause();
final Duration pausedPosition = _controller.value.position;
await tester.pumpAndSettle(_playDuration);

// Verify that we stopped playing after the pause.
expect(_controller.value.isPlaying, false);
expect(_controller.value.position, pausedPosition);
}, skip: (kIsWeb || defaultTargetPlatform == TargetPlatform.macOS));

testWidgets('can show video player', (WidgetTester tester) async {
Future<bool> started() async {
await _controller.initialize();
await _controller.play();
Expand Down Expand Up @@ -159,8 +238,8 @@ void main() {
),
));

await tester.pumpAndSettle();
await tester.pumpAndSettle(_playDuration);
expect(_controller.value.isPlaying, true);
}, skip: kIsWeb); // Web does not support local assets.
}, skip: (kIsWeb || defaultTargetPlatform == TargetPlatform.macOS));
});
}
2 changes: 1 addition & 1 deletion packages/video_player/video_player/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: video_player
description: Flutter plugin for displaying inline video with other Flutter
widgets on Android, iOS, and web.
version: 2.0.2
version: 2.0.3
homepage: https://github.com/flutter/plugins/tree/master/packages/video_player/video_player

flutter:
Expand Down
3 changes: 3 additions & 0 deletions packages/video_player/video_player_macos/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 0.0.1

* Initial release.
1 change: 1 addition & 0 deletions packages/video_player/video_player_macos/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TODO: Add your license here.
34 changes: 34 additions & 0 deletions packages/video_player/video_player_macos/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# video_player_macos

The macos implementation of [`video_player`][1].

## Usage

### Import the package

This package has been endorsed, meaning that you only need to add `video_player`
as a dependency in your `pubspec.yaml`. It will be automatically included in your app
when you depend on `package:video_player`.

This is what the above means to your `pubspec.yaml`:

```yaml
...
dependencies:
...
video_player: ^2.0.3
...
```

If you wish to use the macos package only, you can add `video_player_macos` as a
dependency:

```yaml
...
dependencies:
...
video_player_macos: ^0.0.1
...
```

[1]: ../video_player/video_player
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lib/generated_plugin_registrant.dart
10 changes: 10 additions & 0 deletions packages/video_player/video_player_macos/example/.metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
revision: c5a4b4029c0798f37c4a39b479d7cb75daa7b05c
channel: beta

project_type: app
8 changes: 8 additions & 0 deletions packages/video_player/video_player_macos/example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# video_player_example

Demonstrates how to use the video_player plugin.

## Getting Started

For help getting started with Flutter, view our online
[documentation](https://flutter.dev/).
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
1
00:00:00,200 --> 00:00:01,750
[ Birds chirping ]

2
00:00:02,300 --> 00:00:05,000
[ Buzzing ]
Loading

0 comments on commit 4ed8995

Please sign in to comment.