mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
feat: 直播画质切换
Closes #146 Co-authored-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
43
lib/models/live/quality.dart
Normal file
43
lib/models/live/quality.dart
Normal file
@@ -0,0 +1,43 @@
|
||||
enum LiveQuality {
|
||||
dolby,
|
||||
super4K,
|
||||
origin,
|
||||
veryHigh,
|
||||
bluRay,
|
||||
superHD,
|
||||
smooth,
|
||||
flunt,
|
||||
}
|
||||
|
||||
extension LiveQualityCode on LiveQuality {
|
||||
static final List<int> _codeList = [
|
||||
30000,
|
||||
20000,
|
||||
10000,
|
||||
400,
|
||||
250,
|
||||
150,
|
||||
80,
|
||||
];
|
||||
int get code => _codeList[index];
|
||||
|
||||
static LiveQuality? fromCode(int code) {
|
||||
final index = _codeList.indexOf(code);
|
||||
if (index != -1) {
|
||||
return LiveQuality.values[index];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
extension VideoQualityDesc on LiveQuality {
|
||||
static final List<String> _descList = [
|
||||
'杜比',
|
||||
'4K',
|
||||
'原画',
|
||||
'蓝光',
|
||||
'超清',
|
||||
'流畅',
|
||||
];
|
||||
get description => _descList[index];
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:PiliPlus/models/live/danmu_info.dart';
|
||||
import 'package:PiliPlus/models/live/quality.dart';
|
||||
import 'package:PiliPlus/tcp/live.dart';
|
||||
import 'package:PiliPlus/utils/danmaku.dart';
|
||||
import 'package:PiliPlus/utils/storage.dart';
|
||||
@@ -31,6 +32,10 @@ class LiveRoomController extends GetxController {
|
||||
DanmakuController? controller;
|
||||
bool showDanmaku = true;
|
||||
|
||||
late int currentQn = 10000;
|
||||
late List<Map> acceptQnList = <Map>[];
|
||||
RxString currentQnDesc = ''.obs;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
@@ -58,12 +63,26 @@ class LiveRoomController extends GetxController {
|
||||
bool? isPortrait;
|
||||
|
||||
Future queryLiveInfo() async {
|
||||
var res = await LiveHttp.liveRoomInfo(roomId: roomId, qn: 10000);
|
||||
var res = await LiveHttp.liveRoomInfo(roomId: roomId, qn: currentQn);
|
||||
if (res['status']) {
|
||||
isPortrait = res['data'].isPortrait;
|
||||
List<CodecItem> codec =
|
||||
res['data'].playurlInfo.playurl.stream.first.format.first.codec;
|
||||
CodecItem item = codec.first;
|
||||
// 以服务端返回的码率为准
|
||||
currentQn = item.currentQn!;
|
||||
List acceptQn = item.acceptQn!;
|
||||
acceptQnList = acceptQn.map((e) {
|
||||
return {
|
||||
'code': e,
|
||||
'desc': LiveQuality.values
|
||||
.firstWhere((element) => element.code == e)
|
||||
.description,
|
||||
};
|
||||
}).toList();
|
||||
currentQnDesc.value = LiveQuality.values
|
||||
.firstWhere((element) => element.code == currentQn)
|
||||
.description;
|
||||
String videoUrl = VideoUtils.getCdnUrl(item);
|
||||
await playerInit(videoUrl);
|
||||
return res;
|
||||
@@ -183,4 +202,16 @@ class LiveRoomController extends GetxController {
|
||||
scrollController.dispose();
|
||||
super.onClose();
|
||||
}
|
||||
|
||||
// 修改画质
|
||||
void changeQn(int qn) async {
|
||||
if (currentQn == qn) {
|
||||
return;
|
||||
}
|
||||
currentQn = qn;
|
||||
currentQnDesc.value = LiveQuality.values
|
||||
.firstWhere((element) => element.code == currentQn)
|
||||
.description;
|
||||
await queryLiveInfo();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,14 +5,15 @@ import 'package:flutter/material.dart';
|
||||
import 'package:PiliPlus/models/video/play/url.dart';
|
||||
import 'package:PiliPlus/pages/live_room/index.dart';
|
||||
import 'package:PiliPlus/plugin/pl_player/index.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class BottomControl extends StatefulWidget implements PreferredSizeWidget {
|
||||
final PlPlayerController? controller;
|
||||
final LiveRoomController? liveRoomCtr;
|
||||
final PlPlayerController controller;
|
||||
final LiveRoomController liveRoomCtr;
|
||||
final Floating? floating;
|
||||
const BottomControl({
|
||||
this.controller,
|
||||
this.liveRoomCtr,
|
||||
required this.controller,
|
||||
required this.liveRoomCtr,
|
||||
this.floating,
|
||||
super.key,
|
||||
});
|
||||
@@ -87,7 +88,7 @@ class _BottomControlState extends State<BottomControl> {
|
||||
),
|
||||
onPressed: () async {
|
||||
bool canUsePiP = false;
|
||||
widget.controller!.hiddenControls(false);
|
||||
widget.controller.hiddenControls(false);
|
||||
try {
|
||||
canUsePiP = await widget.floating!.isPipAvailable;
|
||||
} catch (_) {}
|
||||
@@ -104,6 +105,31 @@ class _BottomControlState extends State<BottomControl> {
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
],
|
||||
SizedBox(
|
||||
width: 30,
|
||||
child: PopupMenuButton<int>(
|
||||
padding: EdgeInsets.zero,
|
||||
initialValue: widget.liveRoomCtr.currentQn,
|
||||
onSelected: (value) {
|
||||
widget.liveRoomCtr.changeQn(value);
|
||||
},
|
||||
child: Obx(
|
||||
() => Text(
|
||||
widget.liveRoomCtr.currentQnDesc.value,
|
||||
style: const TextStyle(color: Colors.white, fontSize: 13),
|
||||
),
|
||||
),
|
||||
itemBuilder: (BuildContext context) {
|
||||
return widget.liveRoomCtr.acceptQnList.map((e) {
|
||||
return PopupMenuItem<int>(
|
||||
value: e['code'],
|
||||
child: Text(e['desc']),
|
||||
);
|
||||
}).toList();
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
ComBtn(
|
||||
icon: const Icon(
|
||||
Icons.fullscreen,
|
||||
@@ -111,8 +137,8 @@ class _BottomControlState extends State<BottomControl> {
|
||||
size: 20,
|
||||
color: Colors.white,
|
||||
),
|
||||
fuc: () => widget.controller!.triggerFullScreen(
|
||||
status: !widget.controller!.isFullScreen.value),
|
||||
fuc: () => widget.controller.triggerFullScreen(
|
||||
status: !widget.controller.isFullScreen.value),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user