Skip to content

Commit

Permalink
Merge branch 'feature-liveRoomRender'
Browse files Browse the repository at this point in the history
  • Loading branch information
guozhigq committed Mar 16, 2024
2 parents a57f5e8 + 33d28f5 commit 25d1ccc
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 5 deletions.
43 changes: 43 additions & 0 deletions lib/models/live/quality.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
enum LiveQuality {
dolby,
super4K,
origin,
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];
}
40 changes: 39 additions & 1 deletion lib/pages/live_room/controller.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:pilipala/http/constants.dart';
import 'package:pilipala/http/live.dart';
import 'package:pilipala/models/live/quality.dart';
import 'package:pilipala/models/live/room_info.dart';
import 'package:pilipala/plugin/pl_player/index.dart';
import '../../models/live/room_info_h5.dart';
Expand All @@ -19,10 +21,16 @@ class LiveRoomController extends GetxController {
PlPlayerController.getInstance(videoType: 'live');
Rx<RoomInfoH5Model> roomInfoH5 = RoomInfoH5Model().obs;
late bool enableCDN;
late int currentQn;
int? tempCurrentQn;
late List<Map<String, dynamic>> acceptQnList;
RxString currentQnDesc = ''.obs;

@override
void onInit() {
super.onInit();
currentQn = setting.get(SettingBoxKey.defaultLiveQa,
defaultValue: LiveQuality.values.last.code);
roomId = int.parse(Get.parameters['roomid']!);
if (Get.arguments != null) {
liveItem = Get.arguments['liveItem'];
Expand Down Expand Up @@ -57,11 +65,28 @@ class LiveRoomController extends GetxController {
}

Future queryLiveInfo() async {
var res = await LiveHttp.liveRoomInfo(roomId: roomId, qn: 10000);
var res = await LiveHttp.liveRoomInfo(roomId: roomId, qn: currentQn);
if (res['status']) {
List<CodecItem> codec =
res['data'].playurlInfo.playurl.stream.first.format.first.codec;
CodecItem item = codec.first;
// 以服务端返回的码率为准
currentQn = item.currentQn!;
if (tempCurrentQn != null && tempCurrentQn == currentQn) {
SmartDialog.showToast('画质切换失败,请检查登录状态');
}
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 = enableCDN
? VideoUtils.getCdnUrl(item)
: (item.urlInfo?.first.host)! +
Expand Down Expand Up @@ -90,4 +115,17 @@ class LiveRoomController extends GetxController {
}
return res;
}

// 修改画质
void changeQn(int qn) async {
tempCurrentQn = currentQn;
if (currentQn == qn) {
return;
}
currentQn = qn;
currentQnDesc.value = LiveQuality.values
.firstWhere((element) => element.code == currentQn)
.description;
await queryLiveInfo();
}
}
27 changes: 26 additions & 1 deletion lib/pages/live_room/widgets/bottom_control.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:io';
import 'package:floating/floating.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:hive/hive.dart';
import 'package:pilipala/models/video/play/url.dart';
import 'package:pilipala/pages/live_room/index.dart';
Expand Down Expand Up @@ -83,6 +84,30 @@ class _BottomControlState extends State<BottomControl> {
// ),
// ),
// const SizedBox(width: 4),
SizedBox(
width: 30,
child: PopupMenuButton<int>(
padding: EdgeInsets.zero,
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),
if (Platform.isAndroid) ...[
SizedBox(
width: 34,
Expand Down Expand Up @@ -110,7 +135,7 @@ class _BottomControlState extends State<BottomControl> {
),
),
),
const SizedBox(width: 4),
const SizedBox(width: 10),
],
ComBtn(
icon: const Icon(
Expand Down
36 changes: 33 additions & 3 deletions lib/pages/setting/play_setting.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:pilipala/services/service_locator.dart';
import 'package:pilipala/utils/global_data.dart';
import 'package:pilipala/utils/storage.dart';

import '../../models/live/quality.dart';
import 'widgets/switch_item.dart';

class PlaySetting extends StatefulWidget {
Expand All @@ -22,6 +23,7 @@ class PlaySetting extends StatefulWidget {
class _PlaySettingState extends State<PlaySetting> {
Box setting = GStrorage.setting;
late dynamic defaultVideoQa;
late dynamic defaultLiveQa;
late dynamic defaultAudioQa;
late dynamic defaultDecode;
late int defaultFullScreenMode;
Expand All @@ -32,6 +34,8 @@ class _PlaySettingState extends State<PlaySetting> {
super.initState();
defaultVideoQa = setting.get(SettingBoxKey.defaultVideoQa,
defaultValue: VideoQuality.values.last.code);
defaultLiveQa = setting.get(SettingBoxKey.defaultLiveQa,
defaultValue: LiveQuality.values.last.code);
defaultAudioQa = setting.get(SettingBoxKey.defaultAudioQa,
defaultValue: AudioQuality.values.last.code);
defaultDecode = setting.get(SettingBoxKey.defaultDecode,
Expand Down Expand Up @@ -157,17 +161,17 @@ class _PlaySettingState extends State<PlaySetting> {
}),
ListTile(
dense: false,
title: Text('默认画质', style: titleStyle),
title: Text('默认视频画质', style: titleStyle),
subtitle: Text(
'当前画质${VideoQualityCode.fromCode(defaultVideoQa)!.description!}',
'当前默认画质${VideoQualityCode.fromCode(defaultVideoQa)!.description!}',
style: subTitleStyle,
),
onTap: () async {
int? result = await showDialog(
context: context,
builder: (context) {
return SelectDialog<int>(
title: '默认画质',
title: '默认视频画质',
value: defaultVideoQa,
values: VideoQuality.values.reversed.map((e) {
return {'title': e.description, 'value': e.code};
Expand All @@ -181,6 +185,32 @@ class _PlaySettingState extends State<PlaySetting> {
}
},
),
ListTile(
dense: false,
title: Text('默认直播画质', style: titleStyle),
subtitle: Text(
'当前默认画质${LiveQualityCode.fromCode(defaultLiveQa)!.description!}',
style: subTitleStyle,
),
onTap: () async {
int? result = await showDialog(
context: context,
builder: (context) {
return SelectDialog<int>(
title: '默认直播画质',
value: defaultLiveQa,
values: LiveQuality.values.reversed.map((e) {
return {'title': e.description, 'value': e.code};
}).toList());
},
);
if (result != null) {
defaultLiveQa = result;
setting.put(SettingBoxKey.defaultLiveQa, result);
setState(() {});
}
},
),
ListTile(
dense: false,
title: Text('默认音质', style: titleStyle),
Expand Down
1 change: 1 addition & 0 deletions lib/utils/storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class SettingBoxKey {
autoUpgradeEnable = 'autoUpgradeEnable',
feedBackEnable = 'feedBackEnable',
defaultVideoQa = 'defaultVideoQa',
defaultLiveQa = 'defaultLiveQa',
defaultAudioQa = 'defaultAudioQa',
autoPlayEnable = 'autoPlayEnable',
fullScreenMode = 'fullScreenMode',
Expand Down

0 comments on commit 25d1ccc

Please sign in to comment.