Closed ggdream closed 2 years ago
I'm not sure about that. Could you share your code & be more specific? Is Player.dispose
not working?
Please look:
It stands to reason that when PageView is switched, its child Widget will be destroyed.
In my case, VideoPlayerOther.dispose
should be called, but after debugging, it is not called. I hope can give me some pointers, thank you
PageView.builder(
scrollDirection: Axis.vertical,
onPageChanged: _controller.onPage,
controller: _controller.pageController,
itemCount: _controller.urls.length,
itemBuilder: (context, index) {
if (GetPlatform.isMobile) {
return VideoPlayer(
video: _controller.urls[index],
);
} else if (GetPlatform.isWeb || GetPlatform.isDesktop) {
return VideoPlayerOther(
video: _controller.urls[index],
);
}
return SizedBox();
},
);
})
import 'dart:math';
import 'package:dart_vlc/dart_vlc.dart';
import 'package:flutter/material.dart';
class VideoPlayerOther extends StatefulWidget {
const VideoPlayerOther({
Key? key,
required this.video,
}) : super(key: key);
final String video;
@override
_VideoPlayerOtherState createState() => _VideoPlayerOtherState();
}
class _VideoPlayerOtherState extends State<VideoPlayerOther> {
late final Player _player;
bool _fullScreen = false;
@override
void initState() {
super.initState();
final media = Media.network(widget.video);
_player = Player(id: Random().nextInt(65536))
..setPlaylistMode(PlaylistMode.repeat)
..open(media, autoStart: true);
}
@override
void dispose() {
_player.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return RotatedBox(
quarterTurns: _fullScreen ? 1 : 0,
child: GestureDetector(
onTap: () => _player.playOrPause(),
onLongPress: () {
setState(() {
_fullScreen = !_fullScreen;
});
},
child: Video(
player: _player,
showControls: false,
),
),
);
}
}
Addition:
GetX
VideoPlayer
and VideoPlayerOther
is packaged by itself, dart_vlc
for desktop, fijkplayer
for mobile, and video_player
for WEBSorry to say I don't think this is related to dart_vlc
or it's Native/Dart implementation. Closing.
Please see my code:
Under normal circumstances, the children of PageView are not cached, and the original Widget will be cleared when the page is switched, but the dispose of
xxx()
is not called normally.Want to know what is the reason and how to solve it? thanks