From c924b51220f87709932e6e4be2610b3ecb0b7a74 Mon Sep 17 00:00:00 2001 From: maximencko Date: Tue, 25 Jan 2022 14:01:14 +0200 Subject: [PATCH] feat: prepare player on error on android --- .../flutter/plugins/videoplayer/VideoPlayer.java | 15 +++++---------- .../video_player/lib/video_player.dart | 12 +++++++----- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/packages/video_player/video_player/android/src/main/java/io/flutter/plugins/videoplayer/VideoPlayer.java b/packages/video_player/video_player/android/src/main/java/io/flutter/plugins/videoplayer/VideoPlayer.java index 887d3d15f175..c343d9860195 100644 --- a/packages/video_player/video_player/android/src/main/java/io/flutter/plugins/videoplayer/VideoPlayer.java +++ b/packages/video_player/video_player/android/src/main/java/io/flutter/plugins/videoplayer/VideoPlayer.java @@ -190,26 +190,21 @@ public void onPlaybackStateChanged(final int playbackState) { setBuffering(true); sendBufferingUpdate(); } else if (playbackState == Player.STATE_READY) { - if (!isInitialized) { - isInitialized = true; - sendInitialized(); - } + setBuffering(false); + isInitialized = true; + sendInitialized(); } else if (playbackState == Player.STATE_ENDED) { Map event = new HashMap<>(); event.put("event", "completed"); eventSink.success(event); } - - if (playbackState != Player.STATE_BUFFERING) { - setBuffering(false); - } } @Override public void onPlayerError(final ExoPlaybackException error) { - setBuffering(false); if (eventSink != null) { eventSink.error("VideoError", "Video player had error " + error, null); + exoPlayer.prepare(); } } }); @@ -300,4 +295,4 @@ void dispose() { exoPlayer.release(); } } -} +} \ No newline at end of file diff --git a/packages/video_player/video_player/lib/video_player.dart b/packages/video_player/video_player/lib/video_player.dart index 3d4e1c6aa599..9522b7d54d7b 100644 --- a/packages/video_player/video_player/lib/video_player.dart +++ b/packages/video_player/video_player/lib/video_player.dart @@ -357,7 +357,9 @@ class VideoPlayerController extends ValueNotifier { isInitialized: event.duration != null, errorDescription: null, ); - initializingCompleter.complete(null); + if (!initializingCompleter.isCompleted) { + initializingCompleter.complete(null); + } _applyLooping(); _applyVolume(); _applyPlayPause(); @@ -392,7 +394,7 @@ class VideoPlayerController extends ValueNotifier { void errorListener(Object obj) { final PlatformException e = obj as PlatformException; - value = VideoPlayerValue.erroneous(e.message!); + value = value.copyWith(errorDescription: e.message!); _timer?.cancel(); if (!initializingCompleter.isCompleted) { initializingCompleter.completeError(obj); @@ -788,7 +790,7 @@ class _VideoScrubberState extends State<_VideoScrubber> { } _controllerWasPlaying = controller.value.isPlaying; if (_controllerWasPlaying) { - controller.pause(); + //controller.pause(); } }, onHorizontalDragUpdate: (DragUpdateDetails details) { @@ -800,7 +802,7 @@ class _VideoScrubberState extends State<_VideoScrubber> { onHorizontalDragEnd: (DragEndDetails details) { if (_controllerWasPlaying && controller.value.position != controller.value.duration) { - controller.play(); + //controller.play(); } }, onTapDown: (TapDownDetails details) { @@ -1012,4 +1014,4 @@ class ClosedCaption extends StatelessWidget { /// We use this so that APIs that have become non-nullable can still be used /// with `!` and `?` on the stable branch. // TODO(ianh): Remove this once we roll stable in late 2021. -T? _ambiguate(T? value) => value; +T? _ambiguate(T? value) => value; \ No newline at end of file