Skip to content

Commit ee97b65

Browse files
[video_player] Eliminate platform channel from mock platform (flutter#4588)
1 parent 92539fc commit ee97b65

File tree

5 files changed

+89
-157
lines changed

5 files changed

+89
-157
lines changed

packages/video_player/video_player/CHANGELOG.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
## NEXT
1+
## 2.2.8
22

3+
* Changes the way the `VideoPlayerPlatform` instance is cached in the
4+
controller, so that it's no longer impossible to change after the first use.
5+
* Updates unit tests to be self-contained.
36
* Fixes integration tests.
47
* Updates Android compileSdkVersion to 31.
58
* Fixes a flaky integration test.

packages/video_player/video_player/lib/video_player.dart

+12-4
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,18 @@ export 'package:video_player_platform_interface/video_player_platform_interface.
1717
import 'src/closed_caption_file.dart';
1818
export 'src/closed_caption_file.dart';
1919

20-
final VideoPlayerPlatform _videoPlayerPlatform = VideoPlayerPlatform.instance
21-
// This will clear all open videos on the platform when a full restart is
22-
// performed.
23-
..init();
20+
VideoPlayerPlatform? _lastVideoPlayerPlatform;
21+
22+
VideoPlayerPlatform get _videoPlayerPlatform {
23+
VideoPlayerPlatform currentInstance = VideoPlayerPlatform.instance;
24+
if (_lastVideoPlayerPlatform != currentInstance) {
25+
// This will clear all open videos on the platform when a full restart is
26+
// performed.
27+
currentInstance.init();
28+
_lastVideoPlayerPlatform = currentInstance;
29+
}
30+
return currentInstance;
31+
}
2432

2533
/// The duration, current position, buffering state, error state and settings
2634
/// of a [VideoPlayerController].

packages/video_player/video_player/pubspec.yaml

+1-7
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/master/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.2.7
6+
version: 2.2.8
77

88
environment:
99
sdk: ">=2.14.0 <3.0.0"
@@ -25,12 +25,6 @@ dependencies:
2525
sdk: flutter
2626
meta: ^1.3.0
2727
video_player_platform_interface: ^4.2.0
28-
# The design on https://flutter.dev/go/federated-plugins was to leave
29-
# this constraint as "any". We cannot do it right now as it fails pub publish
30-
# validation, so we set a ^ constraint. The exact value doesn't matter since
31-
# the constraints on the interface pins it.
32-
# TODO(amirh): Revisit this (either update this part in the design or the pub tool).
33-
# https://github.com/flutter/flutter/issues/46264
3428
video_player_web: ^2.0.0
3529
html: ^0.15.0
3630

packages/video_player/video_player/test/video_player_initialization_test.dart

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import 'package:flutter_test/flutter_test.dart';
66
import 'package:video_player/video_player.dart';
7+
import 'package:video_player_platform_interface/video_player_platform_interface.dart';
78

89
import 'video_player_test.dart' show FakeVideoPlayerPlatform;
910

@@ -13,6 +14,7 @@ void main() {
1314
test('plugin initialized', () async {
1415
TestWidgetsFlutterBinding.ensureInitialized();
1516
FakeVideoPlayerPlatform fakeVideoPlayerPlatform = FakeVideoPlayerPlatform();
17+
VideoPlayerPlatform.instance = fakeVideoPlayerPlatform;
1618

1719
final VideoPlayerController controller = VideoPlayerController.network(
1820
'https://127.0.0.1',

0 commit comments

Comments
 (0)