mod: 视频播放器重构 - 基本功能
This commit is contained in:
@ -1,9 +1,9 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_meedu_media_kit/meedu_player.dart';
|
||||
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 = '';
|
||||
@ -13,13 +13,15 @@ class LiveRoomController extends GetxController {
|
||||
double volume = 0.0;
|
||||
// 静音状态
|
||||
RxBool volumeOff = false.obs;
|
||||
PlPlayerController plPlayerController =
|
||||
PlPlayerController(controlsEnabled: false);
|
||||
|
||||
MeeduPlayerController meeduPlayerController = MeeduPlayerController(
|
||||
colorTheme: Theme.of(Get.context!).colorScheme.primary,
|
||||
pipEnabled: true,
|
||||
controlsStyle: ControlsStyle.live,
|
||||
enabledButtons: const EnabledButtons(pip: true),
|
||||
);
|
||||
// MeeduPlayerController meeduPlayerController = MeeduPlayerController(
|
||||
// colorTheme: Theme.of(Get.context!).colorScheme.primary,
|
||||
// pipEnabled: true,
|
||||
// controlsStyle: ControlsStyle.live,
|
||||
// enabledButtons: const EnabledButtons(pip: true),
|
||||
// );
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
@ -36,19 +38,21 @@ class LiveRoomController extends GetxController {
|
||||
}
|
||||
|
||||
playerInit(source) {
|
||||
meeduPlayerController.setDataSource(
|
||||
plPlayerController.setDataSource(
|
||||
DataSource(
|
||||
videoSource: source,
|
||||
audioSource: null,
|
||||
type: DataSourceType.network,
|
||||
source: source,
|
||||
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,
|
||||
);
|
||||
volume = meeduPlayerController.volume.value;
|
||||
}
|
||||
|
||||
Future queryLiveInfo() async {
|
||||
@ -68,12 +72,12 @@ class LiveRoomController extends GetxController {
|
||||
if (value == 0) {
|
||||
// 设置音量
|
||||
volumeOff.value = false;
|
||||
meeduPlayerController.setVolume(volume);
|
||||
// meeduPlayerController.setVolume(volume);
|
||||
} else {
|
||||
// 取消音量
|
||||
volume = value;
|
||||
volumeOff.value = true;
|
||||
meeduPlayerController.setVolume(0);
|
||||
// meeduPlayerController.setVolume(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_meedu_media_kit/meedu_player.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';
|
||||
|
||||
@ -14,7 +14,7 @@ class LiveRoomPage extends StatefulWidget {
|
||||
|
||||
class _LiveRoomPageState extends State<LiveRoomPage> {
|
||||
final LiveRoomController _liveRoomController = Get.put(LiveRoomController());
|
||||
MeeduPlayerController? _meeduPlayerController;
|
||||
PlPlayerController? plPlayerController;
|
||||
|
||||
bool isShowCover = true;
|
||||
bool isPlay = true;
|
||||
@ -22,8 +22,8 @@ class _LiveRoomPageState extends State<LiveRoomPage> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_meeduPlayerController = _liveRoomController.meeduPlayerController;
|
||||
_meeduPlayerController!.onPlayerStatusChanged.listen(
|
||||
plPlayerController = _liveRoomController.plPlayerController;
|
||||
plPlayerController!.onPlayerStatusChanged.listen(
|
||||
(PlayerStatus status) {
|
||||
if (status == PlayerStatus.playing) {
|
||||
isShowCover = false;
|
||||
@ -35,7 +35,7 @@ class _LiveRoomPageState extends State<LiveRoomPage> {
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_meeduPlayerController!.dispose();
|
||||
plPlayerController!.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@ -85,62 +85,33 @@ class _LiveRoomPageState extends State<LiveRoomPage> {
|
||||
body: Column(
|
||||
children: [
|
||||
Hero(
|
||||
tag: _liveRoomController.heroTag,
|
||||
child: Stack(
|
||||
children: [
|
||||
AspectRatio(
|
||||
aspectRatio: 16 / 9,
|
||||
child: MeeduVideoPlayer(
|
||||
header: (BuildContext context,
|
||||
MeeduPlayerController meeduPlayerController,
|
||||
Responsive responsive) {
|
||||
return AppBar(
|
||||
backgroundColor: Colors.transparent,
|
||||
primary: false,
|
||||
elevation: 0,
|
||||
scrolledUnderElevation: 0,
|
||||
foregroundColor: Colors.white,
|
||||
automaticallyImplyLeading: false,
|
||||
centerTitle: false,
|
||||
title: Text(_liveRoomController.liveItem.title,
|
||||
style: const TextStyle(fontSize: 12)),
|
||||
actions: [
|
||||
SizedBox(
|
||||
width: 38,
|
||||
height: 38,
|
||||
child: IconButton(
|
||||
onPressed: () =>
|
||||
meeduPlayerController.enterPip(context),
|
||||
icon: const Icon(
|
||||
Icons.branding_watermark_outlined,
|
||||
size: 19,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12)
|
||||
],
|
||||
);
|
||||
},
|
||||
controller: _meeduPlayerController!,
|
||||
),
|
||||
),
|
||||
if (_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,
|
||||
),
|
||||
tag: _liveRoomController.heroTag,
|
||||
child: Stack(
|
||||
children: [
|
||||
AspectRatio(
|
||||
aspectRatio: 16 / 9,
|
||||
child: plPlayerController!.videoPlayerController != null
|
||||
? PLVideoPlayer(controller: plPlayerController!)
|
||||
: const SizedBox(),
|
||||
),
|
||||
if (_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,
|
||||
),
|
||||
),
|
||||
],
|
||||
)),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (_liveRoomController.liveItem.watchedShow != null)
|
||||
Container(
|
||||
height: 45,
|
||||
@ -153,35 +124,35 @@ class _LiveRoomPageState extends State<LiveRoomPage> {
|
||||
),
|
||||
),
|
||||
child: Row(children: <Widget>[
|
||||
// SizedBox(
|
||||
// width: 38,
|
||||
// height: 38,
|
||||
// child: IconButton(
|
||||
// onPressed: () {},
|
||||
// icon: const Icon(
|
||||
// Icons.subtitles_outlined,
|
||||
// size: 21,
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
SizedBox(
|
||||
width: 38,
|
||||
height: 38,
|
||||
child: IconButton(
|
||||
onPressed: () {},
|
||||
icon: const Icon(
|
||||
Icons.subtitles_outlined,
|
||||
size: 21,
|
||||
),
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
// SizedBox(
|
||||
// width: 38,
|
||||
// height: 38,
|
||||
// child: IconButton(
|
||||
// onPressed: () {},
|
||||
// icon: const Icon(
|
||||
// Icons.hd_outlined,
|
||||
// size: 20,
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
SizedBox(
|
||||
width: 38,
|
||||
height: 38,
|
||||
child: IconButton(
|
||||
onPressed: () {},
|
||||
icon: const Icon(
|
||||
Icons.hd_outlined,
|
||||
size: 20,
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: 38,
|
||||
height: 38,
|
||||
child: IconButton(
|
||||
onPressed: () => _liveRoomController
|
||||
.setVolumn(_meeduPlayerController!.volume.value),
|
||||
.setVolumn(plPlayerController!.volume.value),
|
||||
icon: Obx(() => Icon(
|
||||
_liveRoomController.volumeOff.value
|
||||
? Icons.volume_off_outlined
|
||||
@ -194,8 +165,8 @@ class _LiveRoomPageState extends State<LiveRoomPage> {
|
||||
width: 38,
|
||||
height: 38,
|
||||
child: IconButton(
|
||||
onPressed: () =>
|
||||
_meeduPlayerController!.goToFullscreen(context),
|
||||
onPressed: () => {},
|
||||
// plPlayerController!.goToFullscreen(context),
|
||||
icon: const Icon(
|
||||
Icons.fullscreen,
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user