mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
feat: 解码格式分为首选和次选,调整部分设置文案
This commit is contained in:
@@ -24,6 +24,7 @@ class _PlaySettingState extends State<PlaySetting> {
|
||||
late dynamic defaultVideoQa;
|
||||
late dynamic defaultAudioQa;
|
||||
late dynamic defaultDecode;
|
||||
late dynamic secondDecode;
|
||||
late String defaultSubtitlePreference;
|
||||
late int defaultFullScreenMode;
|
||||
late int defaultBtmProgressBehavior;
|
||||
@@ -37,6 +38,8 @@ class _PlaySettingState extends State<PlaySetting> {
|
||||
defaultValue: AudioQuality.values.last.code);
|
||||
defaultDecode = setting.get(SettingBoxKey.defaultDecode,
|
||||
defaultValue: VideoDecodeFormats.values.last.code);
|
||||
secondDecode = setting.get(SettingBoxKey.secondDecode,
|
||||
defaultValue: VideoDecodeFormats.values[1].code);
|
||||
defaultFullScreenMode = setting.get(SettingBoxKey.fullScreenMode,
|
||||
defaultValue: FullScreenMode.values.first.code);
|
||||
defaultBtmProgressBehavior = setting.get(SettingBoxKey.btmProgressBehavior,
|
||||
@@ -163,7 +166,7 @@ class _PlaySettingState extends State<PlaySetting> {
|
||||
dense: false,
|
||||
title: Text('默认画质', style: titleStyle),
|
||||
subtitle: Text(
|
||||
'当前画质${VideoQualityCode.fromCode(defaultVideoQa)!.description!}',
|
||||
'当前画质:${VideoQualityCode.fromCode(defaultVideoQa)!.description!}',
|
||||
style: subTitleStyle,
|
||||
),
|
||||
onTap: () async {
|
||||
@@ -189,7 +192,7 @@ class _PlaySettingState extends State<PlaySetting> {
|
||||
dense: false,
|
||||
title: Text('默认音质', style: titleStyle),
|
||||
subtitle: Text(
|
||||
'当前音质${AudioQualityCode.fromCode(defaultAudioQa)!.description!}',
|
||||
'当前音质:${AudioQualityCode.fromCode(defaultAudioQa)!.description!}',
|
||||
style: subTitleStyle,
|
||||
),
|
||||
onTap: () async {
|
||||
@@ -213,9 +216,9 @@ class _PlaySettingState extends State<PlaySetting> {
|
||||
),
|
||||
ListTile(
|
||||
dense: false,
|
||||
title: Text('默认解码格式', style: titleStyle),
|
||||
title: Text('首选解码格式', style: titleStyle),
|
||||
subtitle: Text(
|
||||
'当前解码格式${VideoDecodeFormatsCode.fromCode(defaultDecode)!.description!}',
|
||||
'首选解码格式:${VideoDecodeFormatsCode.fromCode(defaultDecode)!.description!},请根据设备支持情况与需求调整',
|
||||
style: subTitleStyle,
|
||||
),
|
||||
onTap: () async {
|
||||
@@ -237,9 +240,35 @@ class _PlaySettingState extends State<PlaySetting> {
|
||||
}
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
dense: false,
|
||||
title: Text('次选解码格式', style: titleStyle),
|
||||
subtitle: Text(
|
||||
'非杜比视频次选:${VideoDecodeFormatsCode.fromCode(secondDecode)!.description!},仍无则选择首个提供的解码格式',
|
||||
style: subTitleStyle,
|
||||
),
|
||||
onTap: () async {
|
||||
String? result = await showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return SelectDialog<String>(
|
||||
title: '次选解码格式',
|
||||
value: secondDecode,
|
||||
values: VideoDecodeFormats.values.map((e) {
|
||||
return {'title': e.description, 'value': e.code};
|
||||
}).toList());
|
||||
},
|
||||
);
|
||||
if (result != null) {
|
||||
secondDecode = result;
|
||||
setting.put(SettingBoxKey.secondDecode, result);
|
||||
setState(() {});
|
||||
}
|
||||
},
|
||||
),
|
||||
const SetSwitchItem(
|
||||
title: '开启硬解',
|
||||
subTitle: '以较低功耗播放视频',
|
||||
subTitle: '以较低功耗播放视频,若使用中异常卡死,请尝试关闭',
|
||||
setKey: SettingBoxKey.enableHA,
|
||||
defaultVal: true,
|
||||
),
|
||||
|
||||
@@ -88,6 +88,7 @@ class VideoDetailController extends GetxController
|
||||
late bool enableCDN;
|
||||
late int? cacheVideoQa;
|
||||
late String cacheDecode;
|
||||
late String cacheSecondDecode;
|
||||
late int cacheAudioQa;
|
||||
|
||||
PersistentBottomSheetController? replyReplyBottomSheetCtr;
|
||||
@@ -136,6 +137,8 @@ class VideoDetailController extends GetxController
|
||||
// 预设的解码格式
|
||||
cacheDecode = setting.get(SettingBoxKey.defaultDecode,
|
||||
defaultValue: VideoDecodeFormats.values.last.code);
|
||||
cacheSecondDecode = setting.get(SettingBoxKey.secondDecode,
|
||||
defaultValue: VideoDecodeFormats.values[1].code);
|
||||
cacheAudioQa = setting.get(SettingBoxKey.defaultAudioQa,
|
||||
defaultValue: AudioQuality.hiRes.code);
|
||||
oid.value = IdUtils.bv2av(Get.parameters['bvid']!);
|
||||
@@ -172,23 +175,52 @@ class VideoDetailController extends GetxController
|
||||
/// 根据currentVideoQa和currentDecodeFormats 重新设置videoUrl
|
||||
List<VideoItem> videoList =
|
||||
data.dash!.video!.where((i) => i.id == currentVideoQa.code).toList();
|
||||
|
||||
final List supportDecodeFormats = videoList.map((e) => e.codecs!).toList();
|
||||
VideoDecodeFormats defaultDecodeFormats =
|
||||
VideoDecodeFormatsCode.fromString(cacheDecode)!;
|
||||
VideoDecodeFormats secondDecodeFormats =
|
||||
VideoDecodeFormatsCode.fromString(cacheSecondDecode)!;
|
||||
try {
|
||||
firstVideo = videoList
|
||||
.firstWhere((i) => i.codecs!.startsWith(currentDecodeFormats.code));
|
||||
} catch (_) {
|
||||
if (currentVideoQa == VideoQuality.dolbyVision) {
|
||||
firstVideo = videoList.first;
|
||||
currentDecodeFormats =
|
||||
VideoDecodeFormatsCode.fromString(videoList.first.codecs!)!;
|
||||
} else {
|
||||
// 当前格式不可用
|
||||
currentDecodeFormats = VideoDecodeFormatsCode.fromString(setting.get(
|
||||
SettingBoxKey.defaultDecode,
|
||||
defaultValue: VideoDecodeFormats.values.last.code))!;
|
||||
firstVideo = videoList
|
||||
.firstWhere((i) => i.codecs!.startsWith(currentDecodeFormats.code));
|
||||
// 当前视频没有对应格式返回第一个
|
||||
int flag = 0;
|
||||
for (var i in supportDecodeFormats) {
|
||||
if (i.startsWith(currentDecodeFormats.code)) {
|
||||
flag = 1;
|
||||
break;
|
||||
} else if (i.startsWith(defaultDecodeFormats.code)) {
|
||||
flag += 2;
|
||||
} else if (i.startsWith(secondDecodeFormats.code)) {
|
||||
flag += 4;
|
||||
}
|
||||
}
|
||||
if (flag == 1) {//currentDecodeFormats
|
||||
firstVideo = videoList.first;
|
||||
} else {
|
||||
if (currentVideoQa == VideoQuality.dolbyVision) {
|
||||
currentDecodeFormats =
|
||||
VideoDecodeFormatsCode.fromString(videoList.first.codecs!)!;
|
||||
firstVideo = videoList.first;
|
||||
} else if (flag == 2 || flag == 6) {//defaultDecodeFormats
|
||||
currentDecodeFormats = defaultDecodeFormats;
|
||||
firstVideo = videoList.firstWhere(
|
||||
(i) => i.codecs!.startsWith(defaultDecodeFormats.code),
|
||||
);
|
||||
} else if (flag == 4) {//secondDecodeFormats
|
||||
currentDecodeFormats = secondDecodeFormats;
|
||||
firstVideo = videoList.firstWhere(
|
||||
(i) => i.codecs!.startsWith(secondDecodeFormats.code),
|
||||
);
|
||||
} else if (flag == 0) {
|
||||
currentDecodeFormats =
|
||||
VideoDecodeFormatsCode.fromString(supportDecodeFormats.first)!;
|
||||
firstVideo = videoList.first;
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
SmartDialog.showToast('DecodeFormats error: $err');
|
||||
}
|
||||
|
||||
videoUrl = firstVideo.baseUrl!;
|
||||
|
||||
/// 根据currentAudioQa 重新设置audioUrl
|
||||
@@ -292,23 +324,30 @@ class VideoDetailController extends GetxController
|
||||
// 根据画质选编码格式
|
||||
final List supportDecodeFormats =
|
||||
supportFormats.firstWhere((e) => e.quality == resVideoQa).codecs!;
|
||||
// 默认从设置中取AVC
|
||||
// 默认从设置中取AV1
|
||||
currentDecodeFormats = VideoDecodeFormatsCode.fromString(cacheDecode)!;
|
||||
VideoDecodeFormats secondDecodeFormats =
|
||||
VideoDecodeFormatsCode.fromString(cacheSecondDecode)!;
|
||||
try {
|
||||
// 当前视频没有对应格式返回第一个
|
||||
bool flag = false;
|
||||
int flag = 0;
|
||||
for (var i in supportDecodeFormats) {
|
||||
if (i.startsWith(currentDecodeFormats.code)) {
|
||||
flag = true;
|
||||
flag = 1;
|
||||
break;
|
||||
} else if (i.startsWith(secondDecodeFormats.code)) {
|
||||
flag += 2;
|
||||
}
|
||||
}
|
||||
currentDecodeFormats = flag
|
||||
? currentDecodeFormats
|
||||
: VideoDecodeFormatsCode.fromString(supportDecodeFormats.first)!;
|
||||
if (flag == 2) {
|
||||
currentDecodeFormats = secondDecodeFormats;
|
||||
} else if (flag == 0) {
|
||||
currentDecodeFormats =
|
||||
VideoDecodeFormatsCode.fromString(supportDecodeFormats.first)!;
|
||||
}
|
||||
} catch (err) {
|
||||
SmartDialog.showToast('DecodeFormats error: $err');
|
||||
}
|
||||
|
||||
/// 取出符合当前解码格式的videoItem
|
||||
try {
|
||||
firstVideo = videosList.firstWhere(
|
||||
|
||||
@@ -82,6 +82,7 @@ class SettingBoxKey {
|
||||
autoPlayEnable = 'autoPlayEnable',
|
||||
fullScreenMode = 'fullScreenMode',
|
||||
defaultDecode = 'defaultDecode',
|
||||
secondDecode = 'secondDecode',
|
||||
danmakuEnable = 'danmakuEnable',
|
||||
defaultToastOp = 'defaultToastOp',
|
||||
defaultPicQa = 'defaultPicQa',
|
||||
|
||||
Reference in New Issue
Block a user