mod: playCount calc

This commit is contained in:
guozhigq
2024-04-27 15:32:05 +08:00
parent 6490d31d3d
commit 29bdbbfe18
4 changed files with 19 additions and 17 deletions

View File

@ -101,7 +101,7 @@ class PlPlayerController {
bool _isFirstTime = true; bool _isFirstTime = true;
Timer? _timer; Timer? _timer;
late Timer? _timerForSeek; Timer? _timerForSeek;
Timer? _timerForVolume; Timer? _timerForVolume;
Timer? _timerForShowingVolume; Timer? _timerForShowingVolume;
Timer? _timerForGettingVolume; Timer? _timerForGettingVolume;
@ -335,8 +335,10 @@ class PlPlayerController {
}) { }) {
// 如果实例尚未创建,则创建一个新实例 // 如果实例尚未创建,则创建一个新实例
_instance ??= PlPlayerController._(); _instance ??= PlPlayerController._();
_instance!._playerCount.value += 1; if (videoType != 'none') {
_videoType.value = videoType; _instance!._playerCount.value += 1;
_videoType.value = videoType;
}
return _instance!; return _instance!;
} }
@ -1120,9 +1122,6 @@ class PlPlayerController {
} }
Future<void> dispose({String type = 'single'}) async { Future<void> dispose({String type = 'single'}) async {
print('dispose');
print('dispose: ${playerCount.value}');
// 每次减1最后销毁 // 每次减1最后销毁
if (type == 'single' && playerCount.value > 1) { if (type == 'single' && playerCount.value > 1) {
_playerCount.value -= 1; _playerCount.value -= 1;
@ -1132,7 +1131,6 @@ class PlPlayerController {
} }
_playerCount.value = 0; _playerCount.value = 0;
try { try {
print('dispose dispose ---------');
_timer?.cancel(); _timer?.cancel();
_timerForVolume?.cancel(); _timerForVolume?.cancel();
_timerForGettingVolume?.cancel(); _timerForGettingVolume?.cancel();

View File

@ -26,7 +26,7 @@ class VideoPlayerServiceHandler extends BaseAudioHandler with SeekHandler {
static final List<MediaItem> _item = []; static final List<MediaItem> _item = [];
Box setting = GStrorage.setting; Box setting = GStrorage.setting;
bool enableBackgroundPlay = false; bool enableBackgroundPlay = false;
PlPlayerController player = PlPlayerController.getInstance(); PlPlayerController player = PlPlayerController.getInstance(videoType: 'none');
VideoPlayerServiceHandler() { VideoPlayerServiceHandler() {
revalidateSetting(); revalidateSetting();

View File

@ -18,7 +18,7 @@ class AudioSessionHandler {
session.configure(const AudioSessionConfiguration.music()); session.configure(const AudioSessionConfiguration.music());
session.interruptionEventStream.listen((event) { session.interruptionEventStream.listen((event) {
final player = PlPlayerController.getInstance(); final player = PlPlayerController.getInstance(videoType: 'none');
if (event.begin) { if (event.begin) {
if (!player.playerStatus.playing) return; if (!player.playerStatus.playing) return;
switch (event.type) { switch (event.type) {
@ -51,7 +51,7 @@ class AudioSessionHandler {
// 耳机拔出暂停 // 耳机拔出暂停
session.becomingNoisyEventStream.listen((_) { session.becomingNoisyEventStream.listen((_) {
final player = PlPlayerController.getInstance(); final player = PlPlayerController.getInstance(videoType: 'none');
if (player.playerStatus.playing) { if (player.playerStatus.playing) {
player.pause(); player.pause();
} }

View File

@ -29,8 +29,8 @@ class ShutdownTimerService {
return; return;
} }
SmartDialog.showToast("设置 $scheduledExitInMinutes 分钟后定时关闭"); SmartDialog.showToast("设置 $scheduledExitInMinutes 分钟后定时关闭");
_shutdownTimer = Timer(Duration(minutes: scheduledExitInMinutes), _shutdownTimer = Timer(
() => _shutdownDecider()); Duration(minutes: scheduledExitInMinutes), () => _shutdownDecider());
} }
void _showTimeUpButPauseDialog() { void _showTimeUpButPauseDialog() {
@ -59,7 +59,7 @@ class ShutdownTimerService {
// Start the 10-second timer to auto close the dialog // Start the 10-second timer to auto close the dialog
_autoCloseDialogTimer?.cancel(); _autoCloseDialogTimer?.cancel();
_autoCloseDialogTimer = Timer(const Duration(seconds: 10), () { _autoCloseDialogTimer = Timer(const Duration(seconds: 10), () {
SmartDialog.dismiss();// Close the dialog SmartDialog.dismiss(); // Close the dialog
_executeShutdown(); _executeShutdown();
}); });
return AlertDialog( return AlertDialog(
@ -88,7 +88,8 @@ class ShutdownTimerService {
_showShutdownDialog(); _showShutdownDialog();
return; return;
} }
PlPlayerController plPlayerController = PlPlayerController.getInstance(); PlPlayerController plPlayerController =
PlPlayerController.getInstance(videoType: 'none');
if (!exitApp && !waitForPlayingCompleted) { if (!exitApp && !waitForPlayingCompleted) {
if (!plPlayerController.playerStatus.playing) { if (!plPlayerController.playerStatus.playing) {
//仅提示用户 //仅提示用户
@ -108,19 +109,22 @@ class ShutdownTimerService {
//该方法依赖耦合实现,不够优雅 //该方法依赖耦合实现,不够优雅
isWaiting = true; isWaiting = true;
} }
void handleWaitingFinished(){
if(isWaiting){ void handleWaitingFinished() {
if (isWaiting) {
_showShutdownDialog(); _showShutdownDialog();
isWaiting = false; isWaiting = false;
} }
} }
void _executeShutdown() { void _executeShutdown() {
if (exitApp) { if (exitApp) {
//退出app //退出app
exit(0); exit(0);
} else { } else {
//暂停播放 //暂停播放
PlPlayerController plPlayerController = PlPlayerController.getInstance(); PlPlayerController plPlayerController =
PlPlayerController.getInstance(videoType: 'none');
if (plPlayerController.playerStatus.playing) { if (plPlayerController.playerStatus.playing) {
plPlayerController.pause(); plPlayerController.pause();
waitForPlayingCompleted = true; waitForPlayingCompleted = true;