fix: 快速返回首页&销毁播放器

This commit is contained in:
guozhigq
2023-08-24 14:22:15 +08:00
parent 4314b0fc3c
commit e3d561bffd
3 changed files with 34 additions and 30 deletions

View File

@ -97,7 +97,6 @@ class _VideoDetailPageState extends State<VideoDetailPage>
@override
void dispose() {
plPlayerController!.pause();
plPlayerController!.dispose();
super.dispose();
}

View File

@ -483,10 +483,12 @@ class _HeaderControlState extends State<HeaderControl> {
size: 15,
color: Colors.white,
),
fuc: () {
fuc: () async {
// 销毁播放器实例
widget.controller!.dispose(type: 'all');
Get.offAll(const MainApp());
await widget.controller!.dispose(type: 'all');
if (mounted) {
Navigator.popUntil(context, (route) => route.isFirst);
}
},
),
const Spacer(),

View File

@ -760,36 +760,39 @@ class PlPlayerController {
Future<void> dispose({String type = 'single'}) async {
// 每次减1最后销毁
if (type == 'single') {
if (type == 'single' && playerCount.value > 1) {
_playerCount.value -= 1;
_heartDuration = 0;
if (playerCount.value > 0) {
pause();
return;
}
}
_playerCount.value = 0;
try {
_timer?.cancel();
_timerForVolume?.cancel();
_timerForGettingVolume?.cancel();
timerForTrackingMouse?.cancel();
_timerForSeek?.cancel();
videoFitChangedTimer?.cancel();
_position.close();
// _position.close();
_playerEventSubs?.cancel();
_sliderPosition.close();
_sliderTempPosition.close();
_isSliderMoving.close();
_duration.close();
_buffered.close();
_showControls.close();
_controlsLock.close();
// _sliderPosition.close();
// _sliderTempPosition.close();
// _isSliderMoving.close();
// _duration.close();
// _buffered.close();
// _showControls.close();
// _controlsLock.close();
playerStatus.status.close();
dataStatus.status.close();
// playerStatus.status.close();
// dataStatus.status.close();
removeListeners();
await _videoPlayerController?.dispose();
_videoPlayerController = null;
_instance = null;
} catch (err) {
print(err);
}
}
}