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

Commit 496e238

Browse files
committed
[video_player] Add macOS implementation
1 parent f7096d7 commit 496e238

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+2913
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 0.0.1
2+
3+
* Initial release.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TODO: Add your license here.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# video_player_macos
2+
3+
The macos implementation of [`video_player`][1].
4+
5+
## Usage
6+
7+
### Import the package
8+
9+
This package has been endorsed, meaning that you only need to add `video_player`
10+
as a dependency in your `pubspec.yaml`. It will be automatically included in your app
11+
when you depend on `package:video_player`.
12+
13+
This is what the above means to your `pubspec.yaml`:
14+
15+
```yaml
16+
...
17+
dependencies:
18+
...
19+
video_player: ^2.0.3
20+
...
21+
```
22+
23+
If you wish to use the macos package only, you can add `video_player_macos` as a
24+
dependency:
25+
26+
```yaml
27+
...
28+
dependencies:
29+
...
30+
video_player_macos: ^0.0.1
31+
...
32+
```
33+
34+
[1]: ../video_player/video_player
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lib/generated_plugin_registrant.dart
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This file tracks properties of this Flutter project.
2+
# Used by Flutter tool to assess capabilities and perform upgrades etc.
3+
#
4+
# This file should be version controlled and should not be manually edited.
5+
6+
version:
7+
revision: c5a4b4029c0798f37c4a39b479d7cb75daa7b05c
8+
channel: beta
9+
10+
project_type: app
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# video_player_example
2+
3+
Demonstrates how to use the video_player plugin.
4+
5+
## Getting Started
6+
7+
For help getting started with Flutter, view our online
8+
[documentation](https://flutter.dev/).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
1
2+
00:00:00,200 --> 00:00:01,750
3+
[ Birds chirping ]
4+
5+
2
6+
00:00:02,300 --> 00:00:05,000
7+
[ Buzzing ]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
// Copyright 2019, the Chromium project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
// TODO(amirh): Remove this once flutter_driver supports null safety.
6+
// https://github.com/flutter/flutter/issues/71379
7+
// @dart = 2.9
8+
import 'dart:async';
9+
10+
import 'package:flutter/material.dart';
11+
import 'package:integration_test/integration_test.dart';
12+
import 'package:flutter_test/flutter_test.dart';
13+
import 'package:video_player/video_player.dart';
14+
15+
const Duration _playDuration = Duration(seconds: 1);
16+
17+
void main() {
18+
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
19+
VideoPlayerController _controller;
20+
tearDown(() async => _controller.dispose());
21+
22+
group('network videos', () {
23+
setUp(() {
24+
_controller = VideoPlayerController.network(
25+
'https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4',
26+
);
27+
});
28+
29+
testWidgets('can be initialized', (WidgetTester tester) async {
30+
await _controller.initialize();
31+
32+
expect(_controller.value.isInitialized, true);
33+
expect(_controller.value.position, const Duration(seconds: 0));
34+
expect(_controller.value.isPlaying, false);
35+
expect(_controller.value.duration,
36+
const Duration(seconds: 4, milliseconds: 036));
37+
});
38+
39+
testWidgets('can be played', (WidgetTester tester) async {
40+
await _controller.initialize();
41+
await _controller.play();
42+
await tester.pumpAndSettle(_playDuration);
43+
44+
expect(_controller.value.isPlaying, true);
45+
expect(_controller.value.position,
46+
(Duration position) => position > const Duration(seconds: 0));
47+
});
48+
49+
testWidgets('can seek', (WidgetTester tester) async {
50+
await _controller.initialize();
51+
52+
await _controller.seekTo(const Duration(seconds: 3));
53+
54+
expect(_controller.value.position, const Duration(seconds: 3));
55+
});
56+
57+
testWidgets(
58+
'can be paused',
59+
(WidgetTester tester) async {
60+
await _controller.initialize();
61+
// Play for a second, then pause, and then wait a second.
62+
await _controller.play();
63+
await tester.pumpAndSettle(_playDuration);
64+
await _controller.pause();
65+
final Duration pausedPosition = _controller.value.position;
66+
await tester.pumpAndSettle(_playDuration);
67+
68+
// Verify that we stopped playing after the pause.
69+
expect(_controller.value.isPlaying, false);
70+
expect(_controller.value.position, pausedPosition);
71+
},
72+
);
73+
74+
testWidgets('reports buffering status', (WidgetTester tester) async {
75+
await _controller.initialize();
76+
final Completer<void> started = Completer();
77+
final Completer<void> ended = Completer();
78+
bool startedBuffering = false;
79+
bool endedBuffering = false;
80+
_controller.addListener(
81+
() {
82+
if (_controller.value.isBuffering && !startedBuffering) {
83+
startedBuffering = true;
84+
started.complete();
85+
}
86+
if (startedBuffering &&
87+
!_controller.value.isBuffering &&
88+
!endedBuffering) {
89+
endedBuffering = true;
90+
ended.complete();
91+
}
92+
},
93+
);
94+
95+
await _controller.play();
96+
await _controller.seekTo(const Duration(seconds: 5));
97+
await tester.pumpAndSettle(_playDuration);
98+
await _controller.pause();
99+
100+
expect(_controller.value.isPlaying, false);
101+
expect(_controller.value.position,
102+
(Duration position) => position > const Duration(seconds: 0));
103+
104+
await started;
105+
expect(startedBuffering, true);
106+
107+
await ended;
108+
expect(endedBuffering, true);
109+
});
110+
111+
testWidgets('can show video player', (WidgetTester tester) async {
112+
Future<bool> started() async {
113+
await _controller.initialize();
114+
await _controller.play();
115+
return true;
116+
}
117+
118+
await tester.pumpWidget(Material(
119+
elevation: 0,
120+
child: Directionality(
121+
textDirection: TextDirection.ltr,
122+
child: Center(
123+
child: FutureBuilder<bool>(
124+
future: started(),
125+
builder: (BuildContext context, AsyncSnapshot<bool> snapshot) {
126+
if (snapshot.data == true) {
127+
return AspectRatio(
128+
aspectRatio: _controller.value.aspectRatio,
129+
child: VideoPlayer(_controller),
130+
);
131+
} else {
132+
return const Text('waiting for video to load');
133+
}
134+
},
135+
),
136+
),
137+
),
138+
));
139+
140+
await tester.pumpAndSettle(_playDuration);
141+
expect(_controller.value.isPlaying, true);
142+
});
143+
});
144+
}

0 commit comments

Comments
 (0)