Skip to content

Commit

Permalink
use stop instead seek, try to show more error, remove clear
Browse files Browse the repository at this point in the history
  • Loading branch information
orz12 committed Jul 26, 2024
1 parent df84e4a commit da139be
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
37 changes: 24 additions & 13 deletions lib/plugin/pl_player/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -892,17 +892,18 @@ class PlPlayerController {
controls = !hideControls;
// // repeat为true,将从头播放

playerStatus.status.value = PlayerStatus.playing;
await _videoPlayerController?.play();
if (repeat) {
SmartDialog.showToast("repeating");
await seekTo(Duration.zero);
SmartDialog.showToast("repeated");
SmartDialog.showToast("stoping");
// await seekTo(Duration.zero);
await _videoPlayerController?.stop();
SmartDialog.showToast("stopped");
}
playerStatus.status.value = PlayerStatus.playing;
await _videoPlayerController?.play();
// if (!playerStatus.playing) await _videoPlayerController?.playOrPause();

// getCurrentVolume();
// getCurrentBrightness();
getCurrentVolume();
getCurrentBrightness();

// screenManager.setOverlays(false);
}
Expand Down Expand Up @@ -967,8 +968,14 @@ class PlPlayerController {
Future<void> getCurrentVolume() async {
// mac try...catch
try {
_currentVolume.value = (await FlutterVolumeController.getVolume())!;
} catch (_) {}
_currentVolume.value = (await FlutterVolumeController.getVolume()
.onError((error, stackTrace) {
SmartDialog.showToast("get volume error11 $error $stackTrace");
return 0;
}))!;
} catch (e) {
SmartDialog.showToast("get volume error $e");
}
}

Future<void> setVolume(double volumeNew,
Expand Down Expand Up @@ -1002,9 +1009,13 @@ class PlPlayerController {
/// 亮度
Future<void> getCurrentBrightness() async {
try {
_currentBrightness.value = await ScreenBrightness().current;
_currentBrightness.value =
await ScreenBrightness().current.onError((error, stackTrace) {
SmartDialog.showToast("get volume error11 $error $stackTrace");
return 0;
});
} catch (e) {
throw 'Failed to get current brightness';
SmartDialog.showToast("get brightness error $e");
//return 0;
}
}
Expand All @@ -1015,15 +1026,15 @@ class PlPlayerController {
ScreenBrightness().setScreenBrightness(brightness);
// setVideoBrightness();
} catch (e) {
throw 'Failed to set brightness';
SmartDialog.showToast("set brightness error $e");
}
}

Future<void> resetBrightness() async {
try {
await ScreenBrightness().resetScreenBrightness();
} catch (e) {
throw 'Failed to reset brightness';
SmartDialog.showToast("reset brightness error $e");
}
}

Expand Down
7 changes: 5 additions & 2 deletions lib/services/audio_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ class VideoPlayerServiceHandler extends BaseAudioHandler with SeekHandler {
// print(newMediaItem);
// print(newMediaItem.title);
// debugPrint(StackTrace.current.toString());
if (!mediaItem.isClosed) mediaItem.add(newMediaItem);
try {
if (!mediaItem.isClosed) mediaItem.add(newMediaItem);
} catch (e) {
SmartDialog.showToast("setMediaItem error $e");
}
}

Future<void> setPlaybackState(PlayerStatus status, bool isBuffering) async {
Expand Down Expand Up @@ -188,7 +192,6 @@ class VideoPlayerServiceHandler extends BaseAudioHandler with SeekHandler {
"${mediaItem.album}\n"
"${mediaItem.artUri}");
// _item.add(mediaItem);
clear();
setMediaItem(mediaItem);
}

Expand Down

0 comments on commit da139be

Please sign in to comment.