Skip to content

Commit

Permalink
Migrate video player plugin to Dart 2.12 and Flutter 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
wanchao-xu committed Mar 30, 2021
1 parent 9feaec5 commit 89a4938
Show file tree
Hide file tree
Showing 11 changed files with 155 additions and 49 deletions.
8 changes: 8 additions & 0 deletions packages/video_player/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 1.0.0

* Initial release.

## 2.0.0

* Update Dart and Flutter SDK constraints
* Update Flutter copyright information
* Update example and integration_test
* Update platform interface to 2.0.1
* Organize dev_dependencies
2 changes: 1 addition & 1 deletion packages/video_player/LICENSE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved.
Copyright (c) 2017 The Chromium Authors. All rights reserved.
Copyright (c) 2013 The Flutter Authors. All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Expand Down
13 changes: 4 additions & 9 deletions packages/video_player/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ This package is not an _endorsed_ implementation of `video_player`. Therefore, y

```yaml
dependencies:
video_player: ^1.0.1
video_player_tizen: ^1.0.0
video_player: ^2.1.0
video_player_tizen: ^2.0.0
```

Then you can import `video_player` in your Dart code:
Expand All @@ -38,14 +38,9 @@ import 'package:video_player/video_player.dart';

For how to use the plugin, see https://github.com/flutter/plugins/tree/master/packages/video_player/video_player#usage.

## Supported devices
## Limitations

This plugin is supported on these types of devices:

- Galaxy Watch (running Tizen 4.0 or later)
- TV (running Tizen 5.5 or later)

## Limitations on TV
The 'httpheaders' option for 'VideoPlayerController.network' and 'mixWithOthers' option of 'VideoPlayerOptions' will be silently ignored in Tizen platform.

This plugin has some limitations on TV:

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
// Copyright 2019, the Chromium project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// TODO(amirh): Remove this once flutter_driver supports null safety.
// https://github.com/flutter/flutter/issues/71379
// @dart = 2.9
import 'dart:async';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:integration_test/integration_test.dart';
import 'package:flutter_test/flutter_test.dart';
Expand All @@ -22,17 +28,65 @@ void main() {
testWidgets('can be initialized', (WidgetTester tester) async {
await _controller.initialize();

expect(_controller.value.initialized, true);
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));
});

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);

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

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);
Expand All @@ -58,6 +112,9 @@ void main() {
'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();
Expand Down Expand Up @@ -104,6 +161,6 @@ void main() {

await tester.pumpAndSettle();
expect(_controller.value.isPlaying, true);
});
}, skip: kIsWeb); // Web does not support local assets.
});
}
26 changes: 15 additions & 11 deletions packages/video_player/example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

Expand Down Expand Up @@ -45,16 +45,19 @@ class _App extends StatelessWidget {
bottom: const TabBar(
isScrollable: true,
tabs: <Widget>[
Tab(
icon: Icon(Icons.cloud),
text: "Remote",
),
Tab(icon: Icon(Icons.insert_drive_file), text: "Asset"),
Tab(icon: Icon(Icons.cloud), text: "Remote"),
Tab(icon: Icon(Icons.list), text: "List example"),
],
),
),
body: TabBarView(
children: <Widget>[
_ButterFlyAssetVideo(),
_BumbleBeeRemoteVideo(),
_ButterFlyAssetVideo(),
_ButterFlyAssetVideoInList(),
],
),
Expand Down Expand Up @@ -105,7 +108,7 @@ class _ButterFlyAssetVideoInList extends StatelessWidget {

/// A filler card to show the video in a list of scrolling contents.
class _ExampleCard extends StatelessWidget {
const _ExampleCard({Key key, this.title}) : super(key: key);
const _ExampleCard({Key? key, required this.title}) : super(key: key);

final String title;

Expand All @@ -121,13 +124,13 @@ class _ExampleCard extends StatelessWidget {
),
ButtonBar(
children: <Widget>[
FlatButton(
TextButton(
child: const Text('BUY TICKETS'),
onPressed: () {
/* ... */
},
),
FlatButton(
TextButton(
child: const Text('SELL TICKETS'),
onPressed: () {
/* ... */
Expand All @@ -147,7 +150,7 @@ class _ButterFlyAssetVideo extends StatefulWidget {
}

class _ButterFlyAssetVideoState extends State<_ButterFlyAssetVideo> {
VideoPlayerController _controller;
late VideoPlayerController _controller;

@override
void initState() {
Expand Down Expand Up @@ -203,7 +206,7 @@ class _BumbleBeeRemoteVideo extends StatefulWidget {
}

class _BumbleBeeRemoteVideoState extends State<_BumbleBeeRemoteVideo> {
VideoPlayerController _controller;
late VideoPlayerController _controller;

Future<ClosedCaptionFile> _loadCaptions() async {
final String fileContents = await DefaultAssetBundle.of(context)
Expand All @@ -215,7 +218,7 @@ class _BumbleBeeRemoteVideoState extends State<_BumbleBeeRemoteVideo> {
void initState() {
super.initState();
_controller = VideoPlayerController.network(
'http://media.w3.org/2010/05/bunny/trailer.mp4',
'https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4',
closedCaptionFile: _loadCaptions(),
videoPlayerOptions: VideoPlayerOptions(mixWithOthers: true),
);
Expand Down Expand Up @@ -262,7 +265,8 @@ class _BumbleBeeRemoteVideoState extends State<_BumbleBeeRemoteVideo> {
}

class _ControlsOverlay extends StatelessWidget {
const _ControlsOverlay({Key key, this.controller}) : super(key: key);
const _ControlsOverlay({Key? key, required this.controller})
: super(key: key);

static const _examplePlaybackRates = [
0.25,
Expand Down Expand Up @@ -342,7 +346,7 @@ class _PlayerVideoAndPopPage extends StatefulWidget {
}

class _PlayerVideoAndPopPageState extends State<_PlayerVideoAndPopPage> {
VideoPlayerController _videoPlayerController;
late VideoPlayerController _videoPlayerController;
bool startedPlaying = false;

@override
Expand Down
14 changes: 8 additions & 6 deletions packages/video_player/example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
name: video_player_example
description: Demonstrates how to use the video_player plugin.
description: Demonstrates how to use the video_player_tizen plugin.
publish_to: 'none'

dependencies:
flutter:
sdk: flutter
video_player: ^1.0.1
video_player: ^2.1.0
video_player_tizen:
path: ../

Expand All @@ -13,10 +14,11 @@ dev_dependencies:
sdk: flutter
flutter_driver:
sdk: flutter
integration_test: ^0.9.2
integration_test:
sdk: flutter
integration_test_tizen:
path: ../../integration_test/
pedantic: ^1.8.0
pedantic: ^1.10.0

flutter:
uses-material-design: true
Expand All @@ -26,5 +28,5 @@ flutter:
- assets/bumble_bee_captions.srt

environment:
sdk: ">=2.8.0 <3.0.0"
flutter: ">=1.12.13+hotfix.5 <2.0.0"
sdk: ">=2.12.0 <3.0.0"
flutter: ">=2.0.0"
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Copyright 2019, the Chromium project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// TODO(egarciad): Remove once Flutter driver is migrated to null safety.
// @dart = 2.9

import 'dart:async';
import 'dart:convert';
Expand Down
14 changes: 14 additions & 0 deletions packages/video_player/example/test_driver/video_player.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// TODO(egarciad): Remove once Flutter driver is migrated to null safety.
// @dart = 2.9

import 'package:flutter_driver/driver_extension.dart';
import 'package:video_player_example/main.dart' as app;

void main() {
enableFlutterDriverExtension();
app.main();
}
30 changes: 30 additions & 0 deletions packages/video_player/example/test_driver/video_player_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// TODO(egarciad): Remove once Flutter driver is migrated to null safety.
// @dart = 2.9

import 'dart:async';
import 'package:flutter_driver/flutter_driver.dart';
import 'package:test/test.dart';

Future<void> main() async {
final FlutterDriver driver = await FlutterDriver.connect();
tearDownAll(() async {
await driver.close();
});

//TODO(cyanglaz): Use TabBar tabs to navigate between pages after https://github.com/flutter/flutter/issues/16991 is fixed.
//TODO(cyanglaz): Un-skip the test after https://github.com/flutter/flutter/issues/43012 is fixed
test('Push a page contains video and pop back, do not crash.', () async {
final SerializableFinder pushTab = find.byValueKey('push_tab');
await driver.waitFor(pushTab);
await driver.tap(pushTab);
await driver.waitForAbsent(pushTab);
await driver.waitFor(find.byValueKey('home_page'));
await driver.waitUntilNoTransientCallbacks();
final Health health = await driver.checkHealth();
expect(health.status, HealthStatus.ok);
}, skip: 'Cirrus CI currently hangs while playing videos');
}
2 changes: 1 addition & 1 deletion packages/video_player/example/tizen/tizen-manifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="org.tizen.video_player_tizen_example" version="1.0.0" api-version="5.5" xmlns="http://tizen.org/ns/packages">
<manifest package="org.tizen.video_player_tizen_example" version="1.0.0" api-version="6.0" xmlns="http://tizen.org/ns/packages">
<profile name="common"/>
<ui-application appid="org.tizen.video_player_tizen_example" exec="Runner.dll" type="dotnet" multiple="false" taskmanage="true" nodisplay="false" api-version="6" launch_mode="single">
<label>video_player_tizen_example</label>
Expand Down
19 changes: 6 additions & 13 deletions packages/video_player/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
name: video_player_tizen
description: Tizen implementation of the video_player plugin
description: Flutter plugin for displaying inline video with other Flutter
widgets on Tizen.
version: 2.0.0
homepage: https://github.com/flutter-tizen/plugins
version: 1.0.0

flutter:
plugin:
Expand All @@ -11,18 +12,10 @@ flutter:
fileName: video_player_tizen_plugin.h

dependencies:
video_player_platform_interface: ^4.1.0
flutter:
sdk: flutter

dev_dependencies:
test: ^1.3.0
flutter_test:
sdk: flutter
integration_test: ^0.9.2
integration_test_tizen:
path: ../integration_test
pedantic: ^1.8.0

environment:
sdk: ">=2.8.0<3.0.0"
flutter: ">=1.20.0 <2.0.0"
sdk: ">=2.12.0<3.0.0"
flutter: ">=2.0.0"

0 comments on commit 89a4938

Please sign in to comment.