@@ -9,10 +9,11 @@ import 'package:flutter/services.dart';
9
9
import 'package:flutter/material.dart' ;
10
10
import 'package:meta/meta.dart' ;
11
11
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 ();
16
17
17
18
class DurationRange {
18
19
DurationRange (this .start, this .end);
@@ -88,7 +89,9 @@ class VideoPlayerValue {
88
89
final Size size;
89
90
90
91
bool get initialized => duration != null ;
92
+
91
93
bool get hasError => errorDescription != null ;
94
+
92
95
double get aspectRatio => size != null ? size.width / size.height : 1.0 ;
93
96
94
97
VideoPlayerValue copyWith ({
@@ -216,12 +219,8 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
216
219
dataSourceDescription = < String , dynamic > {'uri' : dataSource};
217
220
break ;
218
221
}
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);
225
224
_creatingCompleter.complete (null );
226
225
final Completer <void > initializingCompleter = Completer <void >();
227
226
@@ -294,10 +293,7 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
294
293
_isDisposed = true ;
295
294
_timer? .cancel ();
296
295
await _eventSubscription? .cancel ();
297
- await _channel.invokeMethod <void >(
298
- 'dispose' ,
299
- < String , dynamic > {'textureId' : _textureId},
300
- );
296
+ await VideoPlayerPlatform .instance.dispose (_textureId);
301
297
}
302
298
_lifeCycleObserver.dispose ();
303
299
}
@@ -324,21 +320,15 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
324
320
if (! value.initialized || _isDisposed) {
325
321
return ;
326
322
}
327
- _channel.invokeMethod <void >(
328
- 'setLooping' ,
329
- < String , dynamic > {'textureId' : _textureId, 'looping' : value.isLooping},
330
- );
323
+ VideoPlayerPlatform .instance.setLooping (_textureId, value.isLooping);
331
324
}
332
325
333
326
Future <void > _applyPlayPause () async {
334
327
if (! value.initialized || _isDisposed) {
335
328
return ;
336
329
}
337
330
if (value.isPlaying) {
338
- await _channel.invokeMethod <void >(
339
- 'play' ,
340
- < String , dynamic > {'textureId' : _textureId},
341
- );
331
+ VideoPlayerPlatform .instance.play (_textureId);
342
332
_timer = Timer .periodic (
343
333
const Duration (milliseconds: 500 ),
344
334
(Timer timer) async {
@@ -354,34 +344,23 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
354
344
);
355
345
} else {
356
346
_timer? .cancel ();
357
- await _channel.invokeMethod <void >(
358
- 'pause' ,
359
- < String , dynamic > {'textureId' : _textureId},
360
- );
347
+ VideoPlayerPlatform .instance.pause (_textureId);
361
348
}
362
349
}
363
350
364
351
Future <void > _applyVolume () async {
365
352
if (! value.initialized || _isDisposed) {
366
353
return ;
367
354
}
368
- await _channel.invokeMethod <void >(
369
- 'setVolume' ,
370
- < String , dynamic > {'textureId' : _textureId, 'volume' : value.volume},
371
- );
355
+ VideoPlayerPlatform .instance.setVolume (_textureId, value.volume);
372
356
}
373
357
374
358
/// The position in the current video.
375
359
Future <Duration > get position async {
376
360
if (_isDisposed) {
377
361
return null ;
378
362
}
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);
385
364
}
386
365
387
366
Future <void > seekTo (Duration moment) async {
@@ -393,10 +372,7 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
393
372
} else if (moment < const Duration ()) {
394
373
moment = const Duration ();
395
374
}
396
- await _channel.invokeMethod <void >('seekTo' , < String , dynamic > {
397
- 'textureId' : _textureId,
398
- 'location' : moment.inMilliseconds,
399
- });
375
+ VideoPlayerPlatform .instance.seekTo (_textureId, moment.inMilliseconds);
400
376
value = value.copyWith (position: moment);
401
377
}
402
378
0 commit comments