fix:播放异常黑屏等

This commit is contained in:
orz12
2024-03-13 18:38:09 +08:00
parent 766b85cff1
commit cc6da716bc
9 changed files with 50 additions and 35 deletions

View File

@@ -123,7 +123,9 @@ class MyApp extends StatelessWidget {
DisplayMode preferred = modes.toList().firstWhere((el) => el == f); DisplayMode preferred = modes.toList().firstWhere((el) => el == f);
FlutterDisplayMode.setPreferredMode(preferred); FlutterDisplayMode.setPreferredMode(preferred);
}); });
} catch (_) {} } catch (e) {
SmartDialog.showToast('设置帧率失败:$e', displayTime: const Duration(milliseconds: 500));
}
} }
return DynamicColorBuilder( return DynamicColorBuilder(

View File

@@ -23,8 +23,8 @@ class _EmotePanelState extends State<EmotePanel>
@override @override
void initState() { void initState() {
_futureBuilderFuture = _emotePanelController.getEmote();
super.initState(); super.initState();
_futureBuilderFuture = _emotePanelController.getEmote();
} }
@override @override

View File

@@ -24,8 +24,8 @@ class _HistoryPageState extends State<HistoryPage> {
@override @override
void initState() { void initState() {
_futureBuilderFuture = _historyController.queryHistoryList();
super.initState(); super.initState();
_futureBuilderFuture = _historyController.queryHistoryList();
scrollController = _historyController.scrollController; scrollController = _historyController.scrollController;
scrollController.addListener( scrollController.addListener(
() { () {

View File

@@ -94,7 +94,8 @@ class _RcmdPageState extends State<RcmdPage>
sliver: FutureBuilder( sliver: FutureBuilder(
future: _futureBuilderFuture, future: _futureBuilderFuture,
builder: (context, snapshot) { builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) { if (snapshot.connectionState == ConnectionState.done &&
snapshot.data != null) {
Map data = snapshot.data as Map; Map data = snapshot.data as Map;
if (data['status']) { if (data['status']) {
return Obx( return Obx(
@@ -111,7 +112,7 @@ class _RcmdPageState extends State<RcmdPage>
); );
} else { } else {
return HttpError( return HttpError(
errMsg: data['msg'], errMsg: data == null ? "" : data['msg'],
fn: () { fn: () {
setState(() { setState(() {
_rcmdController.isLoadingMore = true; _rcmdController.isLoadingMore = true;

View File

@@ -268,7 +268,9 @@ class VideoDetailController extends GetxController
// 硬解 // 硬解
enableHA: enableHA.value, enableHA: enableHA.value,
seekTo: seekToTime ?? defaultST, seekTo: seekToTime ?? defaultST,
duration: duration ?? Duration(milliseconds: data.timeLength ?? 0), duration: duration ?? data.timeLength == null
? null
: Duration(milliseconds: data.timeLength!),
// 宽>高 水平 否则 垂直 // 宽>高 水平 否则 垂直
direction: firstVideo.width != null && firstVideo.height != null direction: firstVideo.width != null && firstVideo.height != null
? ((firstVideo.width! - firstVideo.height!) > 0 ? ((firstVideo.width! - firstVideo.height!) > 0

View File

@@ -39,11 +39,11 @@ class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel> {
@override @override
void initState() { void initState() {
super.initState();
_videoReplyReplyController = Get.put( _videoReplyReplyController = Get.put(
VideoReplyReplyController( VideoReplyReplyController(
widget.oid, widget.rpid.toString(), widget.replyType!), widget.oid, widget.rpid.toString(), widget.replyType!),
tag: widget.rpid.toString()); tag: widget.rpid.toString());
super.initState();
// 上拉加载更多 // 上拉加载更多
scrollController = _videoReplyReplyController.scrollController; scrollController = _videoReplyReplyController.scrollController;

View File

@@ -293,10 +293,20 @@ class _VideoDetailPageState extends State<VideoDetailPage>
!videoDetailController.isShowCover.value; !videoDetailController.isShowCover.value;
videoIntroController.isPaused = false; videoIntroController.isPaused = false;
if (autoplay) { if (autoplay) {
await Future.delayed(const Duration(milliseconds: 300)); // await Future.delayed(const Duration(milliseconds: 300));
plPlayerController?.seekTo(videoDetailController.defaultST); if (plPlayerController?.buffered.value == Duration.zero) {
plPlayerController?.play(); plPlayerController?.buffered.listen((p0) {
if (p0 > Duration.zero) {
plPlayerController?.seekTo(videoDetailController.defaultST);
plPlayerController?.play();
}
});
} else {
plPlayerController?.seekTo(videoDetailController.defaultST);
plPlayerController?.play();
}
} }
AutoOrientation.fullAutoMode();
plPlayerController?.addStatusLister(playerListener); plPlayerController?.addStatusLister(playerListener);
if (plPlayerController != null) { if (plPlayerController != null) {
listenFullScreenStatus(); listenFullScreenStatus();

View File

@@ -1063,19 +1063,16 @@ class _HeaderControlState extends State<HeaderControl> {
size: 15, size: 15,
color: Colors.white, color: Colors.white,
), ),
onPressed: () => <Set<void>>{ onPressed: () {
if (widget.controller!.isFullScreen.value) if (widget.controller!.isFullScreen.value) {
<void>{widget.controller!.triggerFullScreen(status: false)} widget.controller!.triggerFullScreen(status: false);
else } else if (MediaQuery.of(context).orientation ==
<void>{ Orientation.landscape &&
if (MediaQuery.of(context).orientation == !horizontalScreen) {
Orientation.landscape && verticalScreenForTwoSeconds();
!horizontalScreen) } else {
{ Get.back();
verticalScreenForTwoSeconds(), }
},
Get.back()
}
}, },
)), )),
if ((videoIntroController.videoDetail.value.title != null) && if ((videoIntroController.videoDetail.value.title != null) &&

View File

@@ -83,8 +83,8 @@ class PlPlayerController {
final Rx<BoxFit> _videoFit = Rx(videoFitType.first['attr']); final Rx<BoxFit> _videoFit = Rx(videoFitType.first['attr']);
final Rx<String> _videoFitDesc = Rx(videoFitType.first['desc']); final Rx<String> _videoFitDesc = Rx(videoFitType.first['desc']);
late StreamSubscription<Duration> _bufferedListenerForVideoFit; late StreamSubscription<DataStatus> _dataListenerForVideoFit;
late StreamSubscription<Duration> _bufferedListenerForEnterFullscreen; late StreamSubscription<DataStatus> _dataListenerForEnterFullscreen;
/// ///
// ignore: prefer_final_fields // ignore: prefer_final_fields
@@ -233,7 +233,6 @@ class PlPlayerController {
late double strokeWidth; late double strokeWidth;
late double danmakuDurationVal; late double danmakuDurationVal;
late List<double> speedsList; late List<double> speedsList;
// 缓存
double? defaultDuration; double? defaultDuration;
late bool enableAutoLongPressSpeed = false; late bool enableAutoLongPressSpeed = false;
@@ -555,10 +554,10 @@ class PlPlayerController {
bool autoEnterFullscreen = GStrorage.setting bool autoEnterFullscreen = GStrorage.setting
.get(SettingBoxKey.enableAutoEnter, defaultValue: false); .get(SettingBoxKey.enableAutoEnter, defaultValue: false);
if (autoEnterFullscreen) { if (autoEnterFullscreen) {
if (buffered.value == Duration.zero) { if (dataStatus.status.value != DataStatus.loaded) {
_bufferedListenerForEnterFullscreen = buffered.listen((status) { _dataListenerForEnterFullscreen = dataStatus.status.listen((status) {
if (status > Duration.zero) { if (status == DataStatus.loaded) {
_bufferedListenerForEnterFullscreen.cancel(); _dataListenerForEnterFullscreen.cancel();
triggerFullScreen(status: true); triggerFullScreen(status: true);
} }
}); });
@@ -930,9 +929,9 @@ class PlPlayerController {
if (attr == BoxFit.none || attr == BoxFit.scaleDown) { if (attr == BoxFit.none || attr == BoxFit.scaleDown) {
if (buffered.value == Duration.zero) { if (buffered.value == Duration.zero) {
attr = BoxFit.contain; attr = BoxFit.contain;
_bufferedListenerForVideoFit = buffered.listen((status) { _dataListenerForVideoFit = dataStatus.status.listen((status) {
if (status > Duration.zero) { if (status == DataStatus.loaded) {
_bufferedListenerForVideoFit.cancel(); _dataListenerForVideoFit.cancel();
int fitValue = int fitValue =
videoStorage.get(VideoBoxKey.cacheVideoFit, defaultValue: 0); videoStorage.get(VideoBoxKey.cacheVideoFit, defaultValue: 0);
var attr = videoFitType[fitValue]['attr']; var attr = videoFitType[fitValue]['attr'];
@@ -1023,9 +1022,13 @@ class PlPlayerController {
// StatusBarControl.setHidden(false, animation: StatusBarAnimation.FADE); // StatusBarControl.setHidden(false, animation: StatusBarAnimation.FADE);
showStatusBar(); showStatusBar();
toggleFullScreen(false); toggleFullScreen(false);
if (!setting.get(SettingBoxKey.horizontalScreen, defaultValue: false) && if (mode == FullScreenMode.none) {
mode != FullScreenMode.none) { return;
}
if (!setting.get(SettingBoxKey.horizontalScreen, defaultValue: false)) {
await verticalScreenForTwoSeconds(); await verticalScreenForTwoSeconds();
} else {
await autoScreen();
} }
} }
} }