Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
## 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
Expand Down
29 changes: 14 additions & 15 deletions packages/video_player/video_player/lib/video_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this hack in general, but we don't have a better alternative right now. I filed flutter/flutter#48586 to expose an engine restart hook to the plugin's platform code.


/// The duration, current position, buffering state, error state and settings
/// of a [VideoPlayerController].
Expand Down Expand Up @@ -229,8 +229,7 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
);
break;
}
_textureId =
await VideoPlayerPlatform.instance.create(dataSourceDescription);
_textureId = await _videoPlayerPlatform.create(dataSourceDescription);
_creatingCompleter.complete(null);
final Completer<void> initializingCompleter = Completer<void>();

Expand Down Expand Up @@ -277,7 +276,7 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
}
}

_eventSubscription = VideoPlayerPlatform.instance
_eventSubscription = _videoPlayerPlatform
.videoEventsFor(_textureId)
.listen(eventListener, onError: errorListener);
return initializingCompleter.future;
Expand All @@ -291,7 +290,7 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
_isDisposed = true;
_timer?.cancel();
await _eventSubscription?.cancel();
await VideoPlayerPlatform.instance.dispose(_textureId);
await _videoPlayerPlatform.dispose(_textureId);
}
_lifeCycleObserver.dispose();
}
Expand Down Expand Up @@ -326,15 +325,15 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
if (!value.initialized || _isDisposed) {
return;
}
await VideoPlayerPlatform.instance.setLooping(_textureId, value.isLooping);
await _videoPlayerPlatform.setLooping(_textureId, value.isLooping);
}

Future<void> _applyPlayPause() async {
if (!value.initialized || _isDisposed) {
return;
}
if (value.isPlaying) {
await VideoPlayerPlatform.instance.play(_textureId);
await _videoPlayerPlatform.play(_textureId);
_timer = Timer.periodic(
const Duration(milliseconds: 500),
(Timer timer) async {
Expand All @@ -350,23 +349,23 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
);
} else {
_timer?.cancel();
await VideoPlayerPlatform.instance.pause(_textureId);
await _videoPlayerPlatform.pause(_textureId);
}
}

Future<void> _applyVolume() async {
if (!value.initialized || _isDisposed) {
return;
}
await VideoPlayerPlatform.instance.setVolume(_textureId, value.volume);
await _videoPlayerPlatform.setVolume(_textureId, value.volume);
}

/// The position in the current video.
Future<Duration> get position async {
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
Expand All @@ -383,7 +382,7 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
} else if (position < const Duration()) {
position = const Duration();
}
await VideoPlayerPlatform.instance.seekTo(_textureId, position);
await _videoPlayerPlatform.seekTo(_textureId, position);
value = value.copyWith(position: position);
}

Expand Down Expand Up @@ -483,7 +482,7 @@ class _VideoPlayerState extends State<VideoPlayer> {
Widget build(BuildContext context) {
return _textureId == null
? Container()
: VideoPlayerPlatform.instance.buildView(_textureId);
: _videoPlayerPlatform.buildView(_textureId);
}
}

Expand Down
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 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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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');
});
}