diff --git a/packages/video_player/video_player/CHANGELOG.md b/packages/video_player/video_player/CHANGELOG.md index f96308b447f4..1c5bc5049993 100644 --- a/packages/video_player/video_player/CHANGELOG.md +++ b/packages/video_player/video_player/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.10.5+2 + +* Make sure the plugin is correctly initialized + ## 0.10.5+1 * Fixes issue where `initialize()` `Future` stalls when failing to load source diff --git a/packages/video_player/video_player/lib/video_player.dart b/packages/video_player/video_player/lib/video_player.dart index c41b47c1cacf..b5527b9e6e2d 100644 --- a/packages/video_player/video_player/lib/video_player.dart +++ b/packages/video_player/video_player/lib/video_player.dart @@ -14,10 +14,10 @@ import 'package:video_player_platform_interface/video_player_platform_interface. export 'package:video_player_platform_interface/video_player_platform_interface.dart' show DurationRange, DataSourceType, VideoFormat; -// This will clear all open videos on the platform when a full restart is -// performed. -// ignore: unused_element -final VideoPlayerPlatform _ = VideoPlayerPlatform.instance..init(); +final VideoPlayerPlatform _videoPlayerPlatform = VideoPlayerPlatform.instance + // This will clear all open videos on the platform when a full restart is + // performed. + ..init(); /// The duration, current position, buffering state, error state and settings /// of a [VideoPlayerController]. @@ -229,8 +229,7 @@ class VideoPlayerController extends ValueNotifier { ); break; } - _textureId = - await VideoPlayerPlatform.instance.create(dataSourceDescription); + _textureId = await _videoPlayerPlatform.create(dataSourceDescription); _creatingCompleter.complete(null); final Completer initializingCompleter = Completer(); @@ -277,7 +276,7 @@ class VideoPlayerController extends ValueNotifier { } } - _eventSubscription = VideoPlayerPlatform.instance + _eventSubscription = _videoPlayerPlatform .videoEventsFor(_textureId) .listen(eventListener, onError: errorListener); return initializingCompleter.future; @@ -291,7 +290,7 @@ class VideoPlayerController extends ValueNotifier { _isDisposed = true; _timer?.cancel(); await _eventSubscription?.cancel(); - await VideoPlayerPlatform.instance.dispose(_textureId); + await _videoPlayerPlatform.dispose(_textureId); } _lifeCycleObserver.dispose(); } @@ -326,7 +325,7 @@ class VideoPlayerController extends ValueNotifier { if (!value.initialized || _isDisposed) { return; } - await VideoPlayerPlatform.instance.setLooping(_textureId, value.isLooping); + await _videoPlayerPlatform.setLooping(_textureId, value.isLooping); } Future _applyPlayPause() async { @@ -334,7 +333,7 @@ class VideoPlayerController extends ValueNotifier { return; } if (value.isPlaying) { - await VideoPlayerPlatform.instance.play(_textureId); + await _videoPlayerPlatform.play(_textureId); _timer = Timer.periodic( const Duration(milliseconds: 500), (Timer timer) async { @@ -350,7 +349,7 @@ class VideoPlayerController extends ValueNotifier { ); } else { _timer?.cancel(); - await VideoPlayerPlatform.instance.pause(_textureId); + await _videoPlayerPlatform.pause(_textureId); } } @@ -358,7 +357,7 @@ class VideoPlayerController extends ValueNotifier { if (!value.initialized || _isDisposed) { return; } - await VideoPlayerPlatform.instance.setVolume(_textureId, value.volume); + await _videoPlayerPlatform.setVolume(_textureId, value.volume); } /// The position in the current video. @@ -366,7 +365,7 @@ class VideoPlayerController extends ValueNotifier { if (_isDisposed) { return null; } - return await VideoPlayerPlatform.instance.getPosition(_textureId); + return await _videoPlayerPlatform.getPosition(_textureId); } /// Sets the video's current timestamp to be at [moment]. The next @@ -383,7 +382,7 @@ class VideoPlayerController extends ValueNotifier { } else if (position < const Duration()) { position = const Duration(); } - await VideoPlayerPlatform.instance.seekTo(_textureId, position); + await _videoPlayerPlatform.seekTo(_textureId, position); value = value.copyWith(position: position); } @@ -483,7 +482,7 @@ class _VideoPlayerState extends State { Widget build(BuildContext context) { return _textureId == null ? Container() - : VideoPlayerPlatform.instance.buildView(_textureId); + : _videoPlayerPlatform.buildView(_textureId); } } diff --git a/packages/video_player/video_player/pubspec.yaml b/packages/video_player/video_player/pubspec.yaml index 33af2872ff14..691acc12c184 100644 --- a/packages/video_player/video_player/pubspec.yaml +++ b/packages/video_player/video_player/pubspec.yaml @@ -1,7 +1,7 @@ name: video_player description: Flutter plugin for displaying inline video with other Flutter widgets on Android and iOS. -version: 0.10.5+1 +version: 0.10.5+2 homepage: https://github.com/flutter/plugins/tree/master/packages/video_player/video_player flutter: diff --git a/packages/video_player/video_player/test/video_player_initialization_test.dart b/packages/video_player/video_player/test/video_player_initialization_test.dart new file mode 100644 index 000000000000..61d28070e948 --- /dev/null +++ b/packages/video_player/video_player/test/video_player_initialization_test.dart @@ -0,0 +1,24 @@ +// Copyright 2019 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/widgets.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:video_player/video_player.dart'; + +import 'video_player_test.dart' show FakeVideoPlayerPlatform; + +void main() { + // This test needs to run first and therefore needs to be the only test + // in this file. + test('plugin initialized', () async { + WidgetsFlutterBinding.ensureInitialized(); + FakeVideoPlayerPlatform fakeVideoPlayerPlatform = FakeVideoPlayerPlatform(); + + final VideoPlayerController controller = VideoPlayerController.network( + 'https://127.0.0.1', + ); + await controller.initialize(); + expect(fakeVideoPlayerPlatform.calls.first.method, 'init'); + }); +}