Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class VideoPlayerController(
result.success(player?.isPlaying == true)
}
"dispose" -> {
dispose()
dispose(false)
result.success(true)
}
"onSizeChanged" -> {
Expand All @@ -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()
}
Expand All @@ -157,7 +157,7 @@ class VideoPlayerController(
}
"onOrientationChanged" -> {
if (mediaEntry?.isVRMediaType == true) {
dispose()
dispose(true)
}
result.success(true)
}
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions lib/src/vr_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ class _VideoPlayerState extends State<VrPlayer> 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;
Expand Down Expand Up @@ -100,7 +101,8 @@ class _VideoPlayerState extends State<VrPlayer> with WidgetsBindingObserver {
return AndroidViewSurface(
controller: controller as AndroidViewController,
hitTestBehavior: PlatformViewHitTestBehavior.opaque,
gestureRecognizers: const <Factory<OneSequenceGestureRecognizer>>{
gestureRecognizers: const <Factory<
OneSequenceGestureRecognizer>>{
Factory(TapGestureRecognizer.new),
},
);
Expand Down