feat: 全屏播放
This commit is contained in:
@ -98,10 +98,12 @@ class _MainAppState extends State<MainApp> with SingleTickerProviderStateMixin {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Box localCache = GStrorage.localCache;
|
||||
double statusBarHeight = MediaQuery.of(context).padding.top;
|
||||
double sheetHeight = MediaQuery.of(context).size.height -
|
||||
MediaQuery.of(context).padding.top -
|
||||
MediaQuery.of(context).size.width * 9 / 16;
|
||||
localCache.put('sheetHeight', sheetHeight);
|
||||
localCache.put('statusBarHeight', statusBarHeight);
|
||||
return Scaffold(
|
||||
body: FadeTransition(
|
||||
opacity: _fadeAnimation!,
|
||||
|
@ -109,21 +109,21 @@ class VideoDetailController extends GetxController
|
||||
/// 根据currentVideoQa 重新设置videoUrl
|
||||
VideoItem firstVideo =
|
||||
data.dash!.video!.firstWhere((i) => i.id == currentVideoQa.code);
|
||||
String videoUrl = firstVideo.baseUrl!;
|
||||
// String videoUrl = firstVideo.baseUrl!;
|
||||
|
||||
/// 根据currentAudioQa 重新设置audioUrl
|
||||
AudioItem firstAudio =
|
||||
data.dash!.audio!.firstWhere((i) => i.id == currentAudioQa.code);
|
||||
String audioUrl = firstAudio.baseUrl ?? '';
|
||||
|
||||
playerInit(videoUrl, audioUrl, defaultST: position);
|
||||
playerInit(firstVideo, audioUrl, defaultST: position);
|
||||
}
|
||||
|
||||
playerInit(source, audioSource,
|
||||
playerInit(firstVideo, audioSource,
|
||||
{Duration defaultST = Duration.zero, int duration = 0}) async {
|
||||
plPlayerController.setDataSource(
|
||||
DataSource(
|
||||
videoSource: source,
|
||||
videoSource: firstVideo.baseUrl,
|
||||
audioSource: audioSource,
|
||||
type: DataSourceType.network,
|
||||
httpHeaders: {
|
||||
@ -137,6 +137,9 @@ class VideoDetailController extends GetxController
|
||||
autoplay: autoPlay.value,
|
||||
seekTo: defaultST,
|
||||
duration: Duration(milliseconds: duration),
|
||||
// 宽>高 水平 否则 垂直
|
||||
direction:
|
||||
firstVideo.width - firstVideo.height > 0 ? 'horizontal' : 'vertical',
|
||||
);
|
||||
}
|
||||
|
||||
@ -153,7 +156,7 @@ class VideoDetailController extends GetxController
|
||||
|
||||
/// 优先顺序 省流模式 -> 设置中指定质量 -> 当前可选的最高质量
|
||||
VideoItem firstVideo = data.dash!.video!.first;
|
||||
String videoUrl = firstVideo.baseUrl!;
|
||||
// String videoUrl = firstVideo.baseUrl!;
|
||||
//
|
||||
currentVideoQa = VideoQualityCode.fromCode(firstVideo.id!)!;
|
||||
|
||||
@ -162,15 +165,17 @@ class VideoDetailController extends GetxController
|
||||
data.dash!.audio!.isNotEmpty ? data.dash!.audio!.first : AudioItem();
|
||||
String audioUrl = firstAudio.baseUrl ?? '';
|
||||
//
|
||||
currentAudioQa = AudioQualityCode.fromCode(firstAudio.id!)!;
|
||||
|
||||
if (firstAudio.id != null) {
|
||||
currentAudioQa = AudioQualityCode.fromCode(firstAudio.id!)!;
|
||||
}
|
||||
playerInit(
|
||||
videoUrl,
|
||||
firstVideo,
|
||||
audioUrl,
|
||||
defaultST: Duration(milliseconds: data.lastPlayTime!),
|
||||
duration: data.timeLength ?? 0,
|
||||
);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void loopHeartBeat() {
|
||||
|
@ -3,6 +3,7 @@ import 'dart:async';
|
||||
import 'package:extended_nested_scroll_view/extended_nested_scroll_view.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:pilipala/common/widgets/network_img_layer.dart';
|
||||
import 'package:pilipala/common/widgets/sliver_header.dart';
|
||||
import 'package:pilipala/pages/video/detail/introduction/widgets/menu_row.dart';
|
||||
@ -11,6 +12,7 @@ import 'package:pilipala/pages/video/detail/controller.dart';
|
||||
import 'package:pilipala/pages/video/detail/introduction/index.dart';
|
||||
import 'package:pilipala/pages/video/detail/related/index.dart';
|
||||
import 'package:pilipala/plugin/pl_player/index.dart';
|
||||
import 'package:pilipala/utils/storage.dart';
|
||||
|
||||
import 'widgets/app_bar.dart';
|
||||
import 'widgets/header_control.dart';
|
||||
@ -32,11 +34,14 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
||||
final ScrollController _extendNestCtr = ScrollController();
|
||||
late StreamController<double> appbarStream;
|
||||
|
||||
bool isPlay = false;
|
||||
PlayerStatus playerStatus = PlayerStatus.playing;
|
||||
bool isShowCover = true;
|
||||
double doubleOffset = 0;
|
||||
|
||||
Box localCache = GStrorage.localCache;
|
||||
late double statusBarHeight;
|
||||
final videoHeight = Get.size.width * 9 / 16;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@ -46,14 +51,12 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
||||
videoDetailController.markHeartBeat();
|
||||
playerStatus = status;
|
||||
if (status == PlayerStatus.playing) {
|
||||
isPlay = false;
|
||||
isShowCover = false;
|
||||
setState(() {});
|
||||
videoDetailController.loopHeartBeat();
|
||||
} else {
|
||||
videoDetailController.timer!.cancel();
|
||||
isPlay = true;
|
||||
setState(() {});
|
||||
// setState(() {});
|
||||
// 播放完成停止 or 切换下一个
|
||||
if (status == PlayerStatus.completed) {
|
||||
// 当只有1p或多p未打开自动播放时,播放完成还原进度条,展示控制栏
|
||||
@ -73,6 +76,8 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
||||
appbarStream.add(offset);
|
||||
},
|
||||
);
|
||||
|
||||
statusBarHeight = localCache.get('statusBarHeight');
|
||||
}
|
||||
|
||||
void continuePlay() async {
|
||||
@ -121,7 +126,6 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final double statusBarHeight = MediaQuery.of(context).padding.top;
|
||||
final videoHeight = MediaQuery.of(context).size.width * 9 / 16;
|
||||
final double pinnedHeaderHeight =
|
||||
statusBarHeight + kToolbarHeight + videoHeight;
|
||||
@ -133,7 +137,9 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
||||
Scaffold(
|
||||
resizeToAvoidBottomInset: false,
|
||||
key: videoDetailController.scaffoldKey,
|
||||
backgroundColor: Colors.transparent,
|
||||
// fix 1px black line
|
||||
// backgroundColor: Colors.transparent,
|
||||
backgroundColor: Theme.of(context).colorScheme.background,
|
||||
body: ExtendedNestedScrollView(
|
||||
controller: _extendNestCtr,
|
||||
headerSliverBuilder:
|
||||
@ -150,8 +156,7 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
||||
backgroundColor: Theme.of(context).colorScheme.background,
|
||||
flexibleSpace: FlexibleSpaceBar(
|
||||
background: Padding(
|
||||
padding: EdgeInsets.only(
|
||||
top: MediaQuery.of(context).padding.top),
|
||||
padding: EdgeInsets.only(top: statusBarHeight),
|
||||
child: LayoutBuilder(
|
||||
builder: (context, boxConstraints) {
|
||||
double maxWidth = boxConstraints.maxWidth;
|
||||
@ -187,33 +192,31 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
||||
),
|
||||
|
||||
/// 关闭自动播放时 手动播放
|
||||
Obx(
|
||||
() => Visibility(
|
||||
visible: isShowCover &&
|
||||
videoDetailController
|
||||
.isEffective.value &&
|
||||
!videoDetailController.autoPlay.value,
|
||||
child: Positioned(
|
||||
right: 12,
|
||||
bottom: 6,
|
||||
child: TextButton.icon(
|
||||
style: ButtonStyle(
|
||||
backgroundColor:
|
||||
MaterialStateProperty
|
||||
.resolveWith((states) {
|
||||
return Theme.of(context)
|
||||
.colorScheme
|
||||
.primaryContainer;
|
||||
}),
|
||||
),
|
||||
onPressed: () => videoDetailController
|
||||
.handlePlay(),
|
||||
icon: const Icon(
|
||||
Icons.play_circle_outline,
|
||||
size: 20,
|
||||
),
|
||||
label: const Text('Play'),
|
||||
Visibility(
|
||||
visible: isShowCover &&
|
||||
videoDetailController
|
||||
.isEffective.value &&
|
||||
!videoDetailController.autoPlay.value,
|
||||
child: Positioned(
|
||||
right: 12,
|
||||
bottom: 6,
|
||||
child: TextButton.icon(
|
||||
style: ButtonStyle(
|
||||
backgroundColor:
|
||||
MaterialStateProperty.resolveWith(
|
||||
(states) {
|
||||
return Theme.of(context)
|
||||
.colorScheme
|
||||
.primaryContainer;
|
||||
}),
|
||||
),
|
||||
onPressed: () =>
|
||||
videoDetailController.handlePlay(),
|
||||
icon: const Icon(
|
||||
Icons.play_circle_outline,
|
||||
size: 20,
|
||||
),
|
||||
label: const Text('Play'),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
Reference in New Issue
Block a user