Skip to content

Commit

Permalink
remove _item and delay setplaybackstate
Browse files Browse the repository at this point in the history
  • Loading branch information
orz12 committed Jul 24, 2024
1 parent a269d5b commit e04df23
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions lib/services/audio_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Future<VideoPlayerServiceHandler> initAudioService() async {
}

class VideoPlayerServiceHandler extends BaseAudioHandler with SeekHandler {
static final List<MediaItem> _item = [];
// static final List<MediaItem> _item = [];
Box setting = GStorage.setting;
bool enableBackgroundPlay = true;
// PlPlayerController player = PlPlayerController.getInstance();
Expand Down Expand Up @@ -112,8 +112,10 @@ class VideoPlayerServiceHandler extends BaseAudioHandler with SeekHandler {
onStatusChange(PlayerStatus status, bool isBuffering) {
if (!enableBackgroundPlay) return;

if (_item.isEmpty) return;
setPlaybackState(status, isBuffering);
// if (_item.isEmpty) return;
Future.delayed(const Duration(milliseconds: 500), () {
setPlaybackState(status, isBuffering);
});
}

onVideoDetailChange(dynamic data, int cid) {
Expand Down Expand Up @@ -159,7 +161,7 @@ class VideoPlayerServiceHandler extends BaseAudioHandler with SeekHandler {
if (mediaItem == null) return;
// print("exist: ${PlPlayerController.instanceExists()}");
if (!PlPlayerController.instanceExists()) return;
_item.add(mediaItem);
// _item.add(mediaItem);
setMediaItem(mediaItem);
}

Expand All @@ -172,15 +174,15 @@ class VideoPlayerServiceHandler extends BaseAudioHandler with SeekHandler {
: AudioProcessingState.idle,
playing: false,
));
if (_item.isNotEmpty) {
_item.removeLast();
}
if (_item.isNotEmpty) {
setMediaItem(_item.last);
// stop();
} else {
clear();
}
// if (_item.isNotEmpty) {
// _item.removeLast();
// }
// if (_item.isNotEmpty) {
// setMediaItem(_item.last);
// // stop();
// } else {
// clear();
// }
}

clear() {
Expand All @@ -192,7 +194,7 @@ class VideoPlayerServiceHandler extends BaseAudioHandler with SeekHandler {
: AudioProcessingState.idle,
playing: false,
));
_item.clear();
// _item.clear();
// stop();
}

Expand Down

0 comments on commit e04df23

Please sign in to comment.