mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
feat: 新增更多CDN选项,且默认单独关闭音频CDN
This commit is contained in:
@@ -18,7 +18,7 @@ class LiveRoomController extends GetxController {
|
||||
PlPlayerController plPlayerController =
|
||||
PlPlayerController.getInstance(videoType: 'live');
|
||||
Rx<RoomInfoH5Model> roomInfoH5 = RoomInfoH5Model().obs;
|
||||
late bool enableCDN;
|
||||
// late bool enableCDN;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
@@ -35,7 +35,7 @@ class LiveRoomController extends GetxController {
|
||||
}
|
||||
}
|
||||
// CDN优化
|
||||
enableCDN = setting.get(SettingBoxKey.enableCDN, defaultValue: true);
|
||||
// enableCDN = setting.get(SettingBoxKey.enableCDN, defaultValue: true);
|
||||
}
|
||||
|
||||
playerInit(source) async {
|
||||
@@ -62,11 +62,7 @@ class LiveRoomController extends GetxController {
|
||||
List<CodecItem> codec =
|
||||
res['data'].playurlInfo.playurl.stream.first.format.first.codec;
|
||||
CodecItem item = codec.first;
|
||||
String videoUrl = enableCDN
|
||||
? VideoUtils.getCdnUrl(item)
|
||||
: (item.urlInfo?.first.host)! +
|
||||
item.baseUrl! +
|
||||
item.urlInfo!.first.extra!;
|
||||
String videoUrl = VideoUtils.getCdnUrl(item);
|
||||
await playerInit(videoUrl);
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -3,8 +3,10 @@ import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:PiliPalaX/models/video/play/quality.dart';
|
||||
import 'package:PiliPalaX/models/video/play/CDN.dart';
|
||||
import 'package:PiliPalaX/pages/setting/widgets/select_dialog.dart';
|
||||
import 'package:PiliPalaX/utils/storage.dart';
|
||||
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
|
||||
|
||||
import 'widgets/switch_item.dart';
|
||||
|
||||
@@ -23,6 +25,7 @@ class _VideoSettingState extends State<VideoSetting> {
|
||||
late dynamic secondDecode;
|
||||
late dynamic hardwareDecoding;
|
||||
late dynamic videoSync;
|
||||
late dynamic defaultCDNService;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -39,6 +42,8 @@ class _VideoSettingState extends State<VideoSetting> {
|
||||
defaultValue: Platform.isAndroid ? 'auto-safe' : 'auto');
|
||||
videoSync =
|
||||
setting.get(SettingBoxKey.videoSync, defaultValue: 'display-resample');
|
||||
defaultCDNService = setting.get(SettingBoxKey.CDNService,
|
||||
defaultValue: CDNService.ali.code);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -80,11 +85,37 @@ class _VideoSettingState extends State<VideoSetting> {
|
||||
setKey: SettingBoxKey.p1080,
|
||||
defaultVal: true,
|
||||
),
|
||||
const SetSwitchItem(
|
||||
title: 'CDN优化',
|
||||
subTitle: '使用优质CDN线路',
|
||||
leading: Icon(Icons.network_check_outlined),
|
||||
setKey: SettingBoxKey.enableCDN,
|
||||
ListTile(
|
||||
title: Text('CDN 设置', style: titleStyle),
|
||||
leading: Icon(MdiIcons.cloudPlusOutline),
|
||||
subtitle: Text(
|
||||
'当前使用:${CDNServiceCode.fromCode(defaultCDNService)!.description},部分 CDN 可能失效,如无法播放请尝试切换',
|
||||
style: subTitleStyle,
|
||||
),
|
||||
onTap: () async {
|
||||
String? result = await showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return SelectDialog<String>(
|
||||
title: 'CDN 设置',
|
||||
value: defaultCDNService,
|
||||
values: CDNService.values.map((e) {
|
||||
return {'title': e.description, 'value': e.code};
|
||||
}).toList());
|
||||
},
|
||||
);
|
||||
if (result != null) {
|
||||
defaultCDNService = result;
|
||||
setting.put(SettingBoxKey.CDNService, result);
|
||||
setState(() {});
|
||||
}
|
||||
},
|
||||
),
|
||||
SetSwitchItem(
|
||||
title: '音频不跟随 CDN 设置',
|
||||
subTitle: '直接采用备用 URL,可解决部分视频无声',
|
||||
leading: Icon(MdiIcons.musicNotePlus),
|
||||
setKey: SettingBoxKey.disableAudioCDN,
|
||||
defaultVal: true,
|
||||
),
|
||||
ListTile(
|
||||
@@ -117,7 +148,7 @@ class _VideoSettingState extends State<VideoSetting> {
|
||||
ListTile(
|
||||
dense: false,
|
||||
title: Text('默认音质', style: titleStyle),
|
||||
leading: const Icon(Icons.audiotrack_outlined),
|
||||
leading: const Icon(Icons.music_video_outlined),
|
||||
subtitle: Text(
|
||||
'当前音质:${AudioQualityCode.fromCode(defaultAudioQa)!.description!}',
|
||||
style: subTitleStyle,
|
||||
|
||||
@@ -86,7 +86,7 @@ class VideoDetailController extends GetxController
|
||||
Floating? floating;
|
||||
late PreferredSizeWidget headerControl;
|
||||
|
||||
late bool enableCDN;
|
||||
// late bool enableCDN;
|
||||
late int? cacheVideoQa;
|
||||
late String cacheDecode;
|
||||
late String cacheSecondDecode;
|
||||
@@ -138,7 +138,8 @@ class VideoDetailController extends GetxController
|
||||
heroTag: heroTag,
|
||||
);
|
||||
// CDN优化
|
||||
enableCDN = setting.get(SettingBoxKey.enableCDN, defaultValue: true);
|
||||
// enableCDN = setting.get(SettingBoxKey.enableCDN, defaultValue: true);
|
||||
|
||||
// 预设的画质
|
||||
cacheVideoQa = setting.get(SettingBoxKey.defaultVideoQa,
|
||||
defaultValue: VideoQuality.values.last.code);
|
||||
@@ -388,9 +389,10 @@ class VideoDetailController extends GetxController
|
||||
(e) => e.codecs!.startsWith(currentDecodeFormats.code),
|
||||
orElse: () => videosList.first);
|
||||
|
||||
videoUrl = enableCDN
|
||||
? VideoUtils.getCdnUrl(firstVideo)
|
||||
: (firstVideo.backupUrl ?? firstVideo.baseUrl!);
|
||||
// videoUrl = enableCDN
|
||||
// ? VideoUtils.getCdnUrl(firstVideo)
|
||||
// : (firstVideo.backupUrl ?? firstVideo.baseUrl!);
|
||||
videoUrl = VideoUtils.getCdnUrl(firstVideo);
|
||||
|
||||
/// 优先顺序 设置中指定质量 -> 当前可选的最高质量
|
||||
late AudioItem? firstAudio;
|
||||
@@ -415,9 +417,10 @@ class VideoDetailController extends GetxController
|
||||
}
|
||||
firstAudio = audiosList.firstWhere((e) => e.id == closestNumber,
|
||||
orElse: () => audiosList.first);
|
||||
audioUrl = enableCDN
|
||||
? VideoUtils.getCdnUrl(firstAudio)
|
||||
: (firstAudio.backupUrl ?? firstAudio.baseUrl!);
|
||||
// audioUrl = enableCDN
|
||||
// ? VideoUtils.getCdnUrl(firstAudio)
|
||||
// : (firstAudio.backupUrl ?? firstAudio.baseUrl!);
|
||||
audioUrl = VideoUtils.getCdnUrl(firstAudio);
|
||||
if (firstAudio.id != null) {
|
||||
currentAudioQa = AudioQualityCode.fromCode(firstAudio.id!)!;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user