mod: format code
This commit is contained in:
83
lib/pages/live_room/controller.dart
Normal file
83
lib/pages/live_room/controller.dart
Normal file
@ -0,0 +1,83 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:pilipala/http/constants.dart';
|
||||
import 'package:pilipala/http/live.dart';
|
||||
import 'package:pilipala/models/live/room_info.dart';
|
||||
import 'package:pilipala/plugin/pl_player/index.dart';
|
||||
|
||||
class LiveRoomController extends GetxController {
|
||||
String cover = '';
|
||||
late int roomId;
|
||||
dynamic liveItem;
|
||||
late String heroTag;
|
||||
double volume = 0.0;
|
||||
// 静音状态
|
||||
RxBool volumeOff = false.obs;
|
||||
PlPlayerController plPlayerController =
|
||||
PlPlayerController.getInstance(videoType: 'live');
|
||||
|
||||
// MeeduPlayerController meeduPlayerController = MeeduPlayerController(
|
||||
// colorTheme: Theme.of(Get.context!).colorScheme.primary,
|
||||
// pipEnabled: true,
|
||||
// controlsStyle: ControlsStyle.live,
|
||||
// enabledButtons: const EnabledButtons(pip: true),
|
||||
// );
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
roomId = int.parse(Get.parameters['roomid']!);
|
||||
if (Get.arguments != null) {
|
||||
liveItem = Get.arguments['liveItem'];
|
||||
heroTag = Get.arguments['heroTag'] ?? '';
|
||||
if (liveItem != null && liveItem.pic != null && liveItem.pic != '') {
|
||||
cover = liveItem.pic;
|
||||
}
|
||||
if (liveItem != null && liveItem.cover != null && liveItem.cover != '') {
|
||||
cover = liveItem.cover;
|
||||
}
|
||||
}
|
||||
queryLiveInfo();
|
||||
}
|
||||
|
||||
playerInit(source) {
|
||||
plPlayerController.setDataSource(
|
||||
DataSource(
|
||||
videoSource: source,
|
||||
audioSource: null,
|
||||
type: DataSourceType.network,
|
||||
httpHeaders: {
|
||||
'user-agent':
|
||||
'Mozilla/5.0 (Macintosh; Intel Mac OS X 13_3_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.4 Safari/605.1.15',
|
||||
'referer': HttpString.baseUrl
|
||||
},
|
||||
),
|
||||
// 硬解
|
||||
enableHA: true,
|
||||
autoplay: true,
|
||||
);
|
||||
}
|
||||
|
||||
Future queryLiveInfo() async {
|
||||
var res = await LiveHttp.liveRoomInfo(roomId: roomId, qn: 10000);
|
||||
if (res['status']) {
|
||||
List<CodecItem> codec =
|
||||
res['data'].playurlInfo.playurl.stream.first.format.first.codec;
|
||||
CodecItem item = codec.first;
|
||||
String videoUrl = (item.urlInfo?.first.host)! +
|
||||
item.baseUrl! +
|
||||
item.urlInfo!.first.extra!;
|
||||
playerInit(videoUrl);
|
||||
}
|
||||
}
|
||||
|
||||
void setVolumn(value) {
|
||||
if (value == 0) {
|
||||
// 设置音量
|
||||
volumeOff.value = false;
|
||||
} else {
|
||||
// 取消音量
|
||||
volume = value;
|
||||
volumeOff.value = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
4
lib/pages/live_room/index.dart
Normal file
4
lib/pages/live_room/index.dart
Normal file
@ -0,0 +1,4 @@
|
||||
library liveroom;
|
||||
|
||||
export './controller.dart';
|
||||
export './view.dart';
|
||||
177
lib/pages/live_room/view.dart
Normal file
177
lib/pages/live_room/view.dart
Normal file
@ -0,0 +1,177 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:floating/floating.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:pilipala/common/widgets/network_img_layer.dart';
|
||||
import 'package:pilipala/plugin/pl_player/index.dart';
|
||||
|
||||
import 'controller.dart';
|
||||
import 'widgets/bottom_control.dart';
|
||||
|
||||
class LiveRoomPage extends StatefulWidget {
|
||||
const LiveRoomPage({super.key});
|
||||
|
||||
@override
|
||||
State<LiveRoomPage> createState() => _LiveRoomPageState();
|
||||
}
|
||||
|
||||
class _LiveRoomPageState extends State<LiveRoomPage> {
|
||||
final LiveRoomController _liveRoomController = Get.put(LiveRoomController());
|
||||
PlPlayerController? plPlayerController;
|
||||
|
||||
bool isShowCover = true;
|
||||
bool isPlay = true;
|
||||
Floating? floating;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
plPlayerController = _liveRoomController.plPlayerController;
|
||||
plPlayerController!.onPlayerStatusChanged.listen(
|
||||
(PlayerStatus status) {
|
||||
if (status == PlayerStatus.playing) {
|
||||
isShowCover = false;
|
||||
setState(() {});
|
||||
}
|
||||
},
|
||||
);
|
||||
if (Platform.isAndroid) {
|
||||
floating = Floating();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
plPlayerController!.dispose();
|
||||
if (floating != null) {
|
||||
floating!.dispose();
|
||||
}
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Widget childWhenDisabled = Scaffold(
|
||||
primary: true,
|
||||
appBar: PreferredSize(
|
||||
preferredSize: Size.fromHeight(
|
||||
MediaQuery.of(context).orientation == Orientation.portrait ? 56 : 0,
|
||||
),
|
||||
child: AppBar(
|
||||
centerTitle: false,
|
||||
titleSpacing: 0,
|
||||
title: _liveRoomController.liveItem != null
|
||||
? Row(
|
||||
children: [
|
||||
NetworkImgLayer(
|
||||
width: 34,
|
||||
height: 34,
|
||||
type: 'avatar',
|
||||
src: _liveRoomController.liveItem.face,
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
_liveRoomController.liveItem.uname,
|
||||
style: const TextStyle(fontSize: 14),
|
||||
),
|
||||
const SizedBox(height: 1),
|
||||
if (_liveRoomController.liveItem.watchedShow != null)
|
||||
Text(
|
||||
_liveRoomController
|
||||
.liveItem.watchedShow['text_large'] ??
|
||||
'',
|
||||
style: const TextStyle(fontSize: 12)),
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
: const SizedBox(),
|
||||
// actions: [
|
||||
// SizedBox(
|
||||
// height: 34,
|
||||
// child: ElevatedButton(onPressed: () {}, child: const Text('关注')),
|
||||
// ),
|
||||
// const SizedBox(width: 12),
|
||||
// ],
|
||||
),
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
Stack(
|
||||
children: [
|
||||
PopScope(
|
||||
canPop: plPlayerController?.isFullScreen.value != true,
|
||||
onPopInvoked: (bool didPop) {
|
||||
if (plPlayerController?.isFullScreen.value == true) {
|
||||
plPlayerController!.triggerFullScreen(status: false);
|
||||
}
|
||||
if (MediaQuery.of(context).orientation ==
|
||||
Orientation.landscape) {
|
||||
verticalScreen();
|
||||
}
|
||||
},
|
||||
child: SizedBox(
|
||||
width: Get.size.width,
|
||||
height: MediaQuery.of(context).orientation ==
|
||||
Orientation.landscape
|
||||
? Get.size.height
|
||||
: Get.size.width * 9 / 16,
|
||||
child: plPlayerController!.videoPlayerController != null
|
||||
? PLVideoPlayer(
|
||||
controller: plPlayerController!,
|
||||
bottomControl: BottomControl(
|
||||
controller: plPlayerController,
|
||||
liveRoomCtr: _liveRoomController,
|
||||
floating: floating,
|
||||
),
|
||||
)
|
||||
: const SizedBox(),
|
||||
),
|
||||
),
|
||||
// if (_liveRoomController.liveItem != null &&
|
||||
// _liveRoomController.liveItem.cover != null)
|
||||
// Visibility(
|
||||
// visible: isShowCover,
|
||||
// child: Positioned(
|
||||
// top: 0,
|
||||
// left: 0,
|
||||
// right: 0,
|
||||
// child: NetworkImgLayer(
|
||||
// type: 'emote',
|
||||
// src: _liveRoomController.liveItem.cover,
|
||||
// width: Get.size.width,
|
||||
// height: videoHeight,
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
Widget childWhenEnabled = AspectRatio(
|
||||
aspectRatio: 16 / 9,
|
||||
child: plPlayerController!.videoPlayerController != null
|
||||
? PLVideoPlayer(
|
||||
controller: plPlayerController!,
|
||||
bottomControl: BottomControl(
|
||||
controller: plPlayerController,
|
||||
liveRoomCtr: _liveRoomController,
|
||||
),
|
||||
)
|
||||
: const SizedBox(),
|
||||
);
|
||||
if (Platform.isAndroid) {
|
||||
return PiPSwitcher(
|
||||
childWhenDisabled: childWhenDisabled,
|
||||
childWhenEnabled: childWhenEnabled,
|
||||
);
|
||||
} else {
|
||||
return childWhenDisabled;
|
||||
}
|
||||
}
|
||||
}
|
||||
146
lib/pages/live_room/widgets/bottom_control.dart
Normal file
146
lib/pages/live_room/widgets/bottom_control.dart
Normal file
@ -0,0 +1,146 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:floating/floating.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:pilipala/models/video/play/url.dart';
|
||||
import 'package:pilipala/pages/live_room/index.dart';
|
||||
import 'package:pilipala/plugin/pl_player/index.dart';
|
||||
import 'package:pilipala/utils/storage.dart';
|
||||
|
||||
class BottomControl extends StatefulWidget implements PreferredSizeWidget {
|
||||
final PlPlayerController? controller;
|
||||
final LiveRoomController? liveRoomCtr;
|
||||
final Floating? floating;
|
||||
const BottomControl({
|
||||
this.controller,
|
||||
this.liveRoomCtr,
|
||||
this.floating,
|
||||
Key? key,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<BottomControl> createState() => _BottomControlState();
|
||||
|
||||
@override
|
||||
Size get preferredSize => throw UnimplementedError();
|
||||
}
|
||||
|
||||
class _BottomControlState extends State<BottomControl> {
|
||||
late PlayUrlModel videoInfo;
|
||||
List<PlaySpeed> playSpeed = PlaySpeed.values;
|
||||
TextStyle subTitleStyle = const TextStyle(fontSize: 12);
|
||||
TextStyle titleStyle = const TextStyle(fontSize: 14);
|
||||
Size get preferredSize => const Size(double.infinity, kToolbarHeight);
|
||||
Box localCache = GStrorage.localCache;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AppBar(
|
||||
backgroundColor: Colors.transparent,
|
||||
foregroundColor: Colors.white,
|
||||
elevation: 0,
|
||||
scrolledUnderElevation: 0,
|
||||
primary: false,
|
||||
centerTitle: false,
|
||||
automaticallyImplyLeading: false,
|
||||
titleSpacing: 14,
|
||||
title: Row(
|
||||
children: [
|
||||
// ComBtn(
|
||||
// icon: const Icon(
|
||||
// Icons.subtitles_outlined,
|
||||
// size: 18,
|
||||
// color: Colors.white,
|
||||
// ),
|
||||
// fuc: () => Get.back(),
|
||||
// ),
|
||||
const Spacer(),
|
||||
// ComBtn(
|
||||
// icon: const Icon(
|
||||
// Icons.hd_outlined,
|
||||
// size: 18,
|
||||
// color: Colors.white,
|
||||
// ),
|
||||
// fuc: () => {},
|
||||
// ),
|
||||
// const SizedBox(width: 4),
|
||||
// Obx(
|
||||
// () => ComBtn(
|
||||
// icon: Icon(
|
||||
// widget.liveRoomCtr!.volumeOff.value
|
||||
// ? Icons.volume_off_outlined
|
||||
// : Icons.volume_up_outlined,
|
||||
// size: 18,
|
||||
// color: Colors.white,
|
||||
// ),
|
||||
// fuc: () => {},
|
||||
// ),
|
||||
// ),
|
||||
// const SizedBox(width: 4),
|
||||
if (Platform.isAndroid) ...[
|
||||
SizedBox(
|
||||
width: 34,
|
||||
height: 34,
|
||||
child: IconButton(
|
||||
style: ButtonStyle(
|
||||
padding: MaterialStateProperty.all(EdgeInsets.zero),
|
||||
),
|
||||
onPressed: () async {
|
||||
bool canUsePiP = false;
|
||||
widget.controller!.hiddenControls(false);
|
||||
try {
|
||||
canUsePiP = await widget.floating!.isPipAvailable;
|
||||
} on PlatformException catch (_) {
|
||||
canUsePiP = false;
|
||||
}
|
||||
if (canUsePiP) {
|
||||
await widget.floating!.enable();
|
||||
} else {}
|
||||
},
|
||||
icon: const Icon(
|
||||
Icons.picture_in_picture_outlined,
|
||||
size: 18,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
],
|
||||
ComBtn(
|
||||
icon: const Icon(
|
||||
Icons.fullscreen,
|
||||
size: 20,
|
||||
color: Colors.white,
|
||||
),
|
||||
fuc: () => widget.controller!.triggerFullScreen(),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class MSliderTrackShape extends RoundedRectSliderTrackShape {
|
||||
@override
|
||||
Rect getPreferredRect({
|
||||
required RenderBox parentBox,
|
||||
Offset offset = Offset.zero,
|
||||
SliderThemeData? sliderTheme,
|
||||
bool isEnabled = false,
|
||||
bool isDiscrete = false,
|
||||
}) {
|
||||
const double trackHeight = 3;
|
||||
final double trackLeft = offset.dx;
|
||||
final double trackTop =
|
||||
offset.dy + (parentBox.size.height - trackHeight) / 2 + 4;
|
||||
final double trackWidth = parentBox.size.width;
|
||||
return Rect.fromLTWH(trackLeft, trackTop, trackWidth, trackHeight);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user