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

Commit fae8db7

Browse files
committed
Use platform interface
1 parent 89d7990 commit fae8db7

File tree

3 files changed

+23
-41
lines changed

3 files changed

+23
-41
lines changed

packages/video_player/video_player/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.10.3
2+
3+
* Port plugin code to use the federated Platform Interface, instead of a MethodChannel directly.
4+
15
## 0.10.2+6
26

37
* Remove AndroidX warnings.

packages/video_player/video_player/lib/video_player.dart

Lines changed: 16 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ import 'package:flutter/services.dart';
99
import 'package:flutter/material.dart';
1010
import 'package:meta/meta.dart';
1111

12-
final MethodChannel _channel = const MethodChannel('flutter.io/videoPlayer')
13-
// This will clear all open videos on the platform when a full restart is
14-
// performed.
15-
..invokeMethod<void>('init');
12+
import 'package:video_player_platform_interface/video_player_platform_interface.dart';
13+
14+
// This will clear all open videos on the platform when a full restart is
15+
// performed.
16+
final VideoPlayerPlatform _ = VideoPlayerPlatform.instance..init();
1617

1718
class DurationRange {
1819
DurationRange(this.start, this.end);
@@ -88,7 +89,9 @@ class VideoPlayerValue {
8889
final Size size;
8990

9091
bool get initialized => duration != null;
92+
9193
bool get hasError => errorDescription != null;
94+
9295
double get aspectRatio => size != null ? size.width / size.height : 1.0;
9396

9497
VideoPlayerValue copyWith({
@@ -216,12 +219,8 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
216219
dataSourceDescription = <String, dynamic>{'uri': dataSource};
217220
break;
218221
}
219-
final Map<String, dynamic> response =
220-
await _channel.invokeMapMethod<String, dynamic>(
221-
'create',
222-
dataSourceDescription,
223-
);
224-
_textureId = response['textureId'];
222+
_textureId =
223+
await VideoPlayerPlatform.instance.create(dataSourceDescription);
225224
_creatingCompleter.complete(null);
226225
final Completer<void> initializingCompleter = Completer<void>();
227226

@@ -294,10 +293,7 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
294293
_isDisposed = true;
295294
_timer?.cancel();
296295
await _eventSubscription?.cancel();
297-
await _channel.invokeMethod<void>(
298-
'dispose',
299-
<String, dynamic>{'textureId': _textureId},
300-
);
296+
await VideoPlayerPlatform.instance.dispose(_textureId);
301297
}
302298
_lifeCycleObserver.dispose();
303299
}
@@ -324,21 +320,15 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
324320
if (!value.initialized || _isDisposed) {
325321
return;
326322
}
327-
_channel.invokeMethod<void>(
328-
'setLooping',
329-
<String, dynamic>{'textureId': _textureId, 'looping': value.isLooping},
330-
);
323+
VideoPlayerPlatform.instance.setLooping(_textureId, value.isLooping);
331324
}
332325

333326
Future<void> _applyPlayPause() async {
334327
if (!value.initialized || _isDisposed) {
335328
return;
336329
}
337330
if (value.isPlaying) {
338-
await _channel.invokeMethod<void>(
339-
'play',
340-
<String, dynamic>{'textureId': _textureId},
341-
);
331+
VideoPlayerPlatform.instance.play(_textureId);
342332
_timer = Timer.periodic(
343333
const Duration(milliseconds: 500),
344334
(Timer timer) async {
@@ -354,34 +344,23 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
354344
);
355345
} else {
356346
_timer?.cancel();
357-
await _channel.invokeMethod<void>(
358-
'pause',
359-
<String, dynamic>{'textureId': _textureId},
360-
);
347+
VideoPlayerPlatform.instance.pause(_textureId);
361348
}
362349
}
363350

364351
Future<void> _applyVolume() async {
365352
if (!value.initialized || _isDisposed) {
366353
return;
367354
}
368-
await _channel.invokeMethod<void>(
369-
'setVolume',
370-
<String, dynamic>{'textureId': _textureId, 'volume': value.volume},
371-
);
355+
VideoPlayerPlatform.instance.setVolume(_textureId, value.volume);
372356
}
373357

374358
/// The position in the current video.
375359
Future<Duration> get position async {
376360
if (_isDisposed) {
377361
return null;
378362
}
379-
return Duration(
380-
milliseconds: await _channel.invokeMethod<int>(
381-
'position',
382-
<String, dynamic>{'textureId': _textureId},
383-
),
384-
);
363+
return await VideoPlayerPlatform.instance.getPosition(_textureId);
385364
}
386365

387366
Future<void> seekTo(Duration moment) async {
@@ -393,10 +372,7 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
393372
} else if (moment < const Duration()) {
394373
moment = const Duration();
395374
}
396-
await _channel.invokeMethod<void>('seekTo', <String, dynamic>{
397-
'textureId': _textureId,
398-
'location': moment.inMilliseconds,
399-
});
375+
VideoPlayerPlatform.instance.seekTo(_textureId, moment.inMilliseconds);
400376
value = value.copyWith(position: moment);
401377
}
402378

packages/video_player/video_player/pubspec.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: video_player
22
description: Flutter plugin for displaying inline video with other Flutter
33
widgets on Android and iOS.
44
author: Flutter Team <[email protected]>
5-
version: 0.10.2+6
5+
version: 0.10.3
66
homepage: https://github.com/flutter/plugins/tree/master/packages/video_player/video_player
77

88
flutter:
@@ -13,6 +13,8 @@ flutter:
1313

1414
dependencies:
1515
meta: "^1.0.5"
16+
video_player_platform_interface: ^1.0.0
17+
1618
flutter:
1719
sdk: flutter
1820

0 commit comments

Comments
 (0)