diff --git a/android/src/main/kotlin/wtf/flutter/vr_player/VideoPlayerController.kt b/android/src/main/kotlin/wtf/flutter/vr_player/VideoPlayerController.kt index 7decdf0..b3e043e 100644 --- a/android/src/main/kotlin/wtf/flutter/vr_player/VideoPlayerController.kt +++ b/android/src/main/kotlin/wtf/flutter/vr_player/VideoPlayerController.kt @@ -117,7 +117,7 @@ class VideoPlayerController( result.success(player?.isPlaying == true) } "dispose" -> { - dispose() + dispose(false) result.success(true) } "onSizeChanged" -> { @@ -135,13 +135,13 @@ class VideoPlayerController( } "fullScreen" -> { if (mediaEntry?.isVRMediaType == true) { - dispose() + dispose(true) } result.success(true) } "onPause" -> { if (mediaEntry?.isVRMediaType == true) { - dispose() + dispose(false) } else { player?.onApplicationPaused() } @@ -157,7 +157,7 @@ class VideoPlayerController( } "onOrientationChanged" -> { if (mediaEntry?.isVRMediaType == true) { - dispose() + dispose(true) } result.success(true) } @@ -330,12 +330,15 @@ class VideoPlayerController( return vrSettings } - fun dispose() { + fun dispose(isRebuilding: Boolean = false) { player?.let { this.videoPlayerState = VideoPlayerState(it.currentPosition, it.isPlaying) - it.destroy() + + if (!isRebuilding) { + it.destroy() + player = null + } } - player = null playerEventStateChanged = null playerEventDurationChanged = null diff --git a/lib/src/vr_player.dart b/lib/src/vr_player.dart index 9461f4c..2052af4 100644 --- a/lib/src/vr_player.dart +++ b/lib/src/vr_player.dart @@ -48,7 +48,8 @@ class _VideoPlayerState extends State with WidgetsBindingObserver { void didUpdateWidget(VrPlayer oldWidget) { super.didUpdateWidget(oldWidget); if (oldWidget.width != widget.width) { - final pixelRatio = Platform.isAndroid ? MediaQuery.of(context).devicePixelRatio : 1; + final pixelRatio = + Platform.isAndroid ? MediaQuery.of(context).devicePixelRatio : 1; final width = widget.width * pixelRatio; final height = widget.height * pixelRatio; @@ -100,7 +101,8 @@ class _VideoPlayerState extends State with WidgetsBindingObserver { return AndroidViewSurface( controller: controller as AndroidViewController, hitTestBehavior: PlatformViewHitTestBehavior.opaque, - gestureRecognizers: const >{ + gestureRecognizers: const >{ Factory(TapGestureRecognizer.new), }, );