mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-05-31 08:08:19 +08:00
opt: live room
Closes #427 Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -57,15 +57,16 @@ class LiveRoomController extends GetxController {
|
||||
// 硬解
|
||||
enableHA: true,
|
||||
autoplay: true,
|
||||
direction: isPortrait.value ? 'vertical' : 'horizontal',
|
||||
);
|
||||
}
|
||||
|
||||
bool? isPortrait;
|
||||
final RxBool isPortrait = false.obs;
|
||||
|
||||
Future queryLiveInfo() async {
|
||||
var res = await LiveHttp.liveRoomInfo(roomId: roomId, qn: currentQn);
|
||||
if (res['status']) {
|
||||
isPortrait = res['data'].isPortrait;
|
||||
isPortrait.value = res['data'].isPortrait ?? false;
|
||||
List<CodecItem> codec =
|
||||
res['data'].playurlInfo.playurl.stream.first.format.first.codec;
|
||||
CodecItem item = codec.first;
|
||||
|
||||
@@ -4,7 +4,9 @@ import 'dart:math';
|
||||
|
||||
import 'package:PiliPlus/http/live.dart';
|
||||
import 'package:PiliPlus/pages/live_room/widgets/chat.dart';
|
||||
import 'package:PiliPlus/utils/extension.dart';
|
||||
import 'package:PiliPlus/utils/utils.dart';
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:canvas_danmaku/canvas_danmaku.dart';
|
||||
import 'package:floating/floating.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -33,6 +35,7 @@ class _LiveRoomPageState extends State<LiveRoomPage>
|
||||
late final PlPlayerController plPlayerController;
|
||||
late Future? _futureBuilder;
|
||||
late Future? _futureBuilderFuture;
|
||||
bool get isFullScreen => plPlayerController.isFullScreen.value;
|
||||
|
||||
bool isShowCover = true;
|
||||
bool isPlay = true;
|
||||
@@ -74,11 +77,6 @@ class _LiveRoomPageState extends State<LiveRoomPage>
|
||||
_updateFontSize();
|
||||
}
|
||||
});
|
||||
// WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
// if (context.orientation == Orientation.landscape) {
|
||||
// plPlayerController.triggerFullScreen(status: true);
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
void _updateFontSize() async {
|
||||
@@ -89,7 +87,7 @@ class _LiveRoomPageState extends State<LiveRoomPage>
|
||||
if (_liveRoomController.controller != null) {
|
||||
_liveRoomController.controller!.updateOption(
|
||||
_liveRoomController.controller!.option.copyWith(
|
||||
fontSize: _getFontSize(plPlayerController.isFullScreen.value),
|
||||
fontSize: _getFontSize(isFullScreen),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -101,7 +99,7 @@ class _LiveRoomPageState extends State<LiveRoomPage>
|
||||
: 15 * plPlayerController.fontSizeFSVal;
|
||||
}
|
||||
|
||||
Future<void> videoSourceInit() async {
|
||||
void videoSourceInit() {
|
||||
_futureBuilder = _liveRoomController.queryLiveInfoH5();
|
||||
plPlayerController = _liveRoomController.plPlayerController;
|
||||
}
|
||||
@@ -117,7 +115,6 @@ class _LiveRoomPageState extends State<LiveRoomPage>
|
||||
_node.dispose();
|
||||
plPlayerController.dispose();
|
||||
_ctr.dispose();
|
||||
_liveRoomController.scrollController.removeListener(() {});
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@@ -133,9 +130,21 @@ class _LiveRoomPageState extends State<LiveRoomPage>
|
||||
|
||||
final GlobalKey videoPlayerKey = GlobalKey();
|
||||
final GlobalKey playerKey = GlobalKey();
|
||||
double? padding;
|
||||
|
||||
Widget videoPlayerPanel([Color? fill]) {
|
||||
return FutureBuilder(
|
||||
return PopScope(
|
||||
canPop: !isFullScreen,
|
||||
onPopInvokedWithResult: (bool didPop, Object? result) {
|
||||
if (isFullScreen) {
|
||||
plPlayerController.triggerFullScreen(status: false);
|
||||
}
|
||||
},
|
||||
child: Listener(
|
||||
onPointerDown: (_) {
|
||||
_node.unfocus();
|
||||
},
|
||||
child: FutureBuilder(
|
||||
key: videoPlayerKey,
|
||||
future: _futureBuilderFuture,
|
||||
builder: (BuildContext context, AsyncSnapshot snapshot) {
|
||||
@@ -162,8 +171,7 @@ class _LiveRoomPageState extends State<LiveRoomPage>
|
||||
_liveRoomController.controller = e;
|
||||
},
|
||||
option: DanmakuOption(
|
||||
fontSize:
|
||||
_getFontSize(plPlayerController.isFullScreen.value),
|
||||
fontSize: _getFontSize(isFullScreen),
|
||||
fontWeight: plPlayerController.fontWeight,
|
||||
area: plPlayerController.showArea,
|
||||
opacity: plPlayerController.opacityVal,
|
||||
@@ -183,6 +191,8 @@ class _LiveRoomPageState extends State<LiveRoomPage>
|
||||
return const SizedBox();
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -191,42 +201,41 @@ class _LiveRoomPageState extends State<LiveRoomPage>
|
||||
color: Colors.black,
|
||||
child: Stack(
|
||||
children: [
|
||||
Positioned.fill(
|
||||
Obx(
|
||||
() => isFullScreen
|
||||
? const SizedBox.shrink()
|
||||
: Positioned.fill(
|
||||
child: Opacity(
|
||||
opacity: 0.6,
|
||||
child: Image.asset(
|
||||
child: _liveRoomController.roomInfoH5.value.roomInfo
|
||||
?.appBackground?.isNotEmpty ==
|
||||
true
|
||||
? CachedNetworkImage(
|
||||
fit: BoxFit.cover,
|
||||
width: Get.width,
|
||||
height: Get.height,
|
||||
imageUrl: _liveRoomController.roomInfoH5.value
|
||||
.roomInfo!.appBackground!.http2https,
|
||||
)
|
||||
: Image.asset(
|
||||
'assets/images/live/default_bg.webp',
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
),
|
||||
),
|
||||
Obx(
|
||||
() => _liveRoomController
|
||||
.roomInfoH5.value.roomInfo?.appBackground?.isNotEmpty ==
|
||||
true
|
||||
? Positioned.fill(
|
||||
child: Opacity(
|
||||
opacity: 0.6,
|
||||
child: NetworkImgLayer(
|
||||
width: Get.width,
|
||||
height: Get.height,
|
||||
type: 'bg',
|
||||
src: _liveRoomController
|
||||
.roomInfoH5.value.roomInfo!.appBackground,
|
||||
),
|
||||
),
|
||||
)
|
||||
: const SizedBox(),
|
||||
),
|
||||
isPortrait
|
||||
? Scaffold(
|
||||
backgroundColor: Colors.transparent,
|
||||
body: Column(
|
||||
children: [
|
||||
_buildAppBar,
|
||||
..._buildBodyP,
|
||||
],
|
||||
),
|
||||
? Obx(
|
||||
() {
|
||||
if (_liveRoomController.isPortrait.value) {
|
||||
if (padding == null) {
|
||||
final padding = MediaQuery.paddingOf(context);
|
||||
this.padding = padding.bottom + padding.top;
|
||||
}
|
||||
return _buildPP;
|
||||
}
|
||||
return _buildPH;
|
||||
},
|
||||
)
|
||||
: Column(
|
||||
children: [
|
||||
@@ -239,6 +248,66 @@ class _LiveRoomPageState extends State<LiveRoomPage>
|
||||
);
|
||||
}
|
||||
|
||||
Widget get _buildPH => Scaffold(
|
||||
appBar: _buildAppBar,
|
||||
backgroundColor: Colors.transparent,
|
||||
body: Column(
|
||||
children: _buildBodyP,
|
||||
),
|
||||
);
|
||||
|
||||
Widget get _buildPP => Scaffold(
|
||||
appBar: _buildAppBar,
|
||||
backgroundColor: Colors.transparent,
|
||||
body: Stack(
|
||||
children: [
|
||||
Column(
|
||||
children: [
|
||||
Obx(
|
||||
() => Container(
|
||||
color: Colors.black,
|
||||
width: Get.width,
|
||||
height: isFullScreen
|
||||
? Get.height -
|
||||
(context.orientation == Orientation.landscape
|
||||
? 0
|
||||
: MediaQuery.paddingOf(context).top)
|
||||
: Get.height - 56 - 85 - padding!,
|
||||
child: videoPlayerPanel(),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Obx(
|
||||
() => isFullScreen
|
||||
? const SizedBox.shrink()
|
||||
: Positioned(
|
||||
left: 0,
|
||||
right: 0,
|
||||
bottom: 125 + MediaQuery.paddingOf(context).bottom,
|
||||
child: SizedBox(
|
||||
height: 125,
|
||||
child: _buildChatWidget,
|
||||
),
|
||||
),
|
||||
),
|
||||
Obx(
|
||||
() => isFullScreen
|
||||
? const SizedBox.shrink()
|
||||
: Positioned(
|
||||
left: 0,
|
||||
right: 0,
|
||||
bottom: 0,
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(bottom: 0),
|
||||
child: _buildInputWidget,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
@@ -262,12 +331,11 @@ class _LiveRoomPageState extends State<LiveRoomPage>
|
||||
|
||||
Color get _color => Color(0xFFEEEEEE);
|
||||
|
||||
Widget get _buildAppBar => Obx(
|
||||
() => AppBar(
|
||||
PreferredSizeWidget get _buildAppBar => AppBar(
|
||||
backgroundColor: Colors.transparent,
|
||||
foregroundColor: Colors.white,
|
||||
toolbarHeight: isFullScreen ? 0 : null,
|
||||
titleTextStyle: TextStyle(color: Colors.white),
|
||||
toolbarHeight: plPlayerController.isFullScreen.value ? 0 : null,
|
||||
title: FutureBuilder(
|
||||
future: _futureBuilder,
|
||||
builder: (context, snapshot) {
|
||||
@@ -282,8 +350,8 @@ class _LiveRoomPageState extends State<LiveRoomPage>
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
_node.unfocus();
|
||||
dynamic uid = _liveRoomController
|
||||
.roomInfoH5.value.roomInfo?.uid;
|
||||
dynamic uid =
|
||||
_liveRoomController.roomInfoH5.value.roomInfo?.uid;
|
||||
Get.toNamed(
|
||||
'/member?mid=$uid',
|
||||
arguments: {
|
||||
@@ -309,8 +377,7 @@ class _LiveRoomPageState extends State<LiveRoomPage>
|
||||
style: const TextStyle(fontSize: 14),
|
||||
),
|
||||
const SizedBox(height: 1),
|
||||
if (_liveRoomController
|
||||
.roomInfoH5.value.watchedShow !=
|
||||
if (_liveRoomController.roomInfoH5.value.watchedShow !=
|
||||
null)
|
||||
Text(
|
||||
_liveRoomController.roomInfoH5.value
|
||||
@@ -349,7 +416,6 @@ class _LiveRoomPageState extends State<LiveRoomPage>
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Widget get _buildBodyH {
|
||||
@@ -359,27 +425,10 @@ class _LiveRoomPageState extends State<LiveRoomPage>
|
||||
child: Row(
|
||||
children: [
|
||||
Obx(
|
||||
() => PopScope(
|
||||
canPop: plPlayerController.isFullScreen.value != true,
|
||||
onPopInvokedWithResult: (bool didPop, Object? result) {
|
||||
if (plPlayerController.isFullScreen.value == true) {
|
||||
plPlayerController.triggerFullScreen(status: false);
|
||||
}
|
||||
},
|
||||
child: Listener(
|
||||
onPointerDown: (_) {
|
||||
_node.unfocus();
|
||||
},
|
||||
child: Container(
|
||||
color: plPlayerController.isFullScreen.value
|
||||
? Colors.black
|
||||
: null,
|
||||
width: plPlayerController.isFullScreen.value
|
||||
? Get.size.width
|
||||
: videoWidth,
|
||||
height: plPlayerController.isFullScreen.value
|
||||
? Get.size.height
|
||||
: Get.size.width * 9 / 16,
|
||||
() => Container(
|
||||
color: Colors.black,
|
||||
width: isFullScreen ? Get.size.width : videoWidth,
|
||||
height: isFullScreen ? Get.size.height : Get.size.width * 9 / 16,
|
||||
child: MediaQuery.removePadding(
|
||||
removeRight: true,
|
||||
context: context,
|
||||
@@ -387,8 +436,6 @@ class _LiveRoomPageState extends State<LiveRoomPage>
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Scaffold(
|
||||
backgroundColor: Colors.transparent,
|
||||
@@ -409,36 +456,24 @@ class _LiveRoomPageState extends State<LiveRoomPage>
|
||||
|
||||
List<Widget> get _buildBodyP => [
|
||||
Obx(
|
||||
() => PopScope(
|
||||
canPop: plPlayerController.isFullScreen.value != true,
|
||||
onPopInvokedWithResult: (bool didPop, Object? result) {
|
||||
if (plPlayerController.isFullScreen.value == true) {
|
||||
plPlayerController.triggerFullScreen(status: false);
|
||||
}
|
||||
},
|
||||
child: Listener(
|
||||
onPointerDown: (_) {
|
||||
_node.unfocus();
|
||||
},
|
||||
child: Container(
|
||||
() => Container(
|
||||
color: Colors.black,
|
||||
width: Get.size.width,
|
||||
height: plPlayerController.isFullScreen.value
|
||||
? Get.size.height
|
||||
: Get.size.width * 9 / 16,
|
||||
height: isFullScreen ? Get.size.height : Get.size.width * 9 / 16,
|
||||
child: videoPlayerPanel(),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
..._buildBottomWidget,
|
||||
];
|
||||
|
||||
final GlobalKey chatKey = GlobalKey();
|
||||
|
||||
List<Widget> get _buildBottomWidget => [
|
||||
Expanded(
|
||||
child: Listener(
|
||||
Expanded(child: _buildChatWidget),
|
||||
_buildInputWidget,
|
||||
];
|
||||
|
||||
Widget get _buildChatWidget => Listener(
|
||||
onPointerDown: (_) {
|
||||
_node.unfocus();
|
||||
},
|
||||
@@ -450,9 +485,9 @@ class _LiveRoomPageState extends State<LiveRoomPage>
|
||||
liveRoomController: _liveRoomController,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
);
|
||||
|
||||
Widget get _buildInputWidget => Container(
|
||||
padding: EdgeInsets.only(
|
||||
left: 10,
|
||||
top: 10,
|
||||
@@ -514,15 +549,11 @@ class _LiveRoomPageState extends State<LiveRoomPage>
|
||||
_onSendMsg(_ctr.text);
|
||||
}
|
||||
},
|
||||
icon: Icon(
|
||||
Icons.send,
|
||||
color: _color,
|
||||
),
|
||||
icon: Icon(Icons.send, color: _color),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
];
|
||||
);
|
||||
|
||||
void _onSendMsg(msg) async {
|
||||
if (!_isLogin) {
|
||||
|
||||
Reference in New Issue
Block a user