Merge branch 'fix'

This commit is contained in:
guozhigq
2024-04-27 12:36:20 +08:00
5 changed files with 91 additions and 49 deletions

View File

@ -39,6 +39,14 @@ extension VideoQualityCode on VideoQuality {
}
return null;
}
static int? toCode(VideoQuality quality) {
final index = VideoQuality.values.indexOf(quality);
if (index != -1 && index < _codeList.length) {
return _codeList[index];
}
return null;
}
}
extension VideoQualityDesc on VideoQuality {

View File

@ -236,6 +236,7 @@ class BangumiIntroController extends GetxController {
videoDetailCtr.bvid = bvid;
videoDetailCtr.cid.value = cid;
videoDetailCtr.danmakuCid.value = cid;
videoDetailCtr.oid.value = aid;
videoDetailCtr.queryVideoUrl();
// 重新请求评论
try {

View File

@ -85,7 +85,9 @@ class _BangumiPanelState extends State<BangumiPanel> {
item.cid,
item.aid,
);
if (_bottomSheetController != null) {
_bottomSheetController?.close();
}
currentIndex = i;
scrollToIndex();
}

View File

@ -51,7 +51,7 @@ class VideoDetailController extends GetxController
/// 播放器配置 画质 音质 解码格式
late VideoQuality currentVideoQa;
AudioQuality? currentAudioQa;
late VideoDecodeFormats currentDecodeFormats;
VideoDecodeFormats? currentDecodeFormats;
// 是否开始自动播放 存在多p的情况下第二p需要为true
RxBool autoPlay = true.obs;
// 视频资源是否有效
@ -107,6 +107,7 @@ class VideoDetailController extends GetxController
BottomControlType.fullscreen,
].obs;
RxDouble sheetHeight = 0.0.obs;
RxString archiveSourceType = 'dash'.obs;
@override
void onInit() {
@ -189,12 +190,13 @@ class VideoDetailController extends GetxController
plPlayerController.isBuffering.value = false;
plPlayerController.buffered.value = Duration.zero;
if (archiveSourceType.value == 'dash') {
/// 根据currentVideoQa和currentDecodeFormats 重新设置videoUrl
List<VideoItem> videoList =
data.dash!.video!.where((i) => i.id == currentVideoQa.code).toList();
try {
firstVideo = videoList
.firstWhere((i) => i.codecs!.startsWith(currentDecodeFormats.code));
firstVideo = videoList.firstWhere(
(i) => i.codecs!.startsWith(currentDecodeFormats?.code));
} catch (_) {
if (currentVideoQa == VideoQuality.dolbyVision) {
firstVideo = videoList.first;
@ -205,8 +207,8 @@ class VideoDetailController extends GetxController
currentDecodeFormats = VideoDecodeFormatsCode.fromString(setting.get(
SettingBoxKey.defaultDecode,
defaultValue: VideoDecodeFormats.values.last.code))!;
firstVideo = videoList
.firstWhere((i) => i.codecs!.startsWith(currentDecodeFormats.code));
firstVideo = videoList.firstWhere(
(i) => i.codecs!.startsWith(currentDecodeFormats?.code));
}
}
videoUrl = firstVideo.baseUrl!;
@ -219,7 +221,12 @@ class VideoDetailController extends GetxController
);
audioUrl = firstAudio.baseUrl ?? '';
}
}
if (archiveSourceType.value == 'durl') {
cacheVideoQa = VideoQualityCode.toCode(currentVideoQa);
queryVideoUrl();
}
playerInit();
}
@ -272,7 +279,8 @@ class VideoDetailController extends GetxController
// 视频链接
Future queryVideoUrl() async {
var result = await VideoHttp.videoUrl(cid: cid.value, bvid: bvid);
var result =
await VideoHttp.videoUrl(cid: cid.value, bvid: bvid, qn: cacheVideoQa);
if (result['status']) {
data = result['data'];
if (data.acceptDesc!.isNotEmpty && data.acceptDesc!.contains('试看')) {
@ -290,8 +298,22 @@ class VideoDetailController extends GetxController
}
return result;
}
if (data.durl != null) {
archiveSourceType.value = 'durl';
videoUrl = data.durl!.first.url!;
audioUrl = '';
defaultST = Duration.zero;
firstVideo = VideoItem();
currentVideoQa = VideoQualityCode.fromCode(data.quality!)!;
if (autoPlay.value) {
await playerInit();
isShowCover.value = false;
}
return result;
}
final List<VideoItem> allVideosList = data.dash!.video!;
try {
archiveSourceType.value = 'dash';
// 当前可播放的最高质量视频
int currentHighVideoQa = allVideosList.first.quality!.code;
// 预设的画质为null则当前可用的最高质量
@ -321,7 +343,7 @@ class VideoDetailController extends GetxController
// 当前视频没有对应格式返回第一个
bool flag = false;
for (var i in supportDecodeFormats) {
if (i.startsWith(currentDecodeFormats.code)) {
if (i.startsWith(currentDecodeFormats?.code)) {
flag = true;
}
}
@ -335,7 +357,7 @@ class VideoDetailController extends GetxController
/// 取出符合当前解码格式的videoItem
try {
firstVideo = videosList.firstWhere(
(e) => e.codecs!.startsWith(currentDecodeFormats.code));
(e) => e.codecs!.startsWith(currentDecodeFormats?.code));
} catch (_) {
firstVideo = videosList.first;
}

View File

@ -180,13 +180,14 @@ class _HeaderControlState extends State<HeaderControl> {
'当前音质 ${widget.videoDetailCtr!.currentAudioQa!.description}',
style: subTitleStyle),
),
if (widget.videoDetailCtr!.currentDecodeFormats != null)
ListTile(
onTap: () => {Get.back(), showSetDecodeFormats()},
dense: true,
leading: const Icon(Icons.av_timer_outlined, size: 20),
title: const Text('解码格式', style: titleStyle),
subtitle: Text(
'当前解码格式 ${widget.videoDetailCtr!.currentDecodeFormats.description}',
'当前解码格式 ${widget.videoDetailCtr!.currentDecodeFormats!.description}',
style: subTitleStyle),
),
ListTile(
@ -541,6 +542,8 @@ class _HeaderControlState extends State<HeaderControl> {
/// 可用的质量分类
int userfulQaSam = 0;
if (videoInfo.dash != null) {
// dash格式视频一次请求会返回所有可播放的清晰度video
final List<VideoItem> video = videoInfo.dash!.video!;
final Set<int> idSet = {};
for (final VideoItem item in video) {
@ -550,6 +553,12 @@ class _HeaderControlState extends State<HeaderControl> {
userfulQaSam++;
}
}
}
if (videoInfo.durl != null) {
// durl格式视频一次请求返回对应清晰度video
userfulQaSam = videoFormat.length - 1;
}
showModalBottomSheet(
context: context,
@ -707,7 +716,7 @@ class _HeaderControlState extends State<HeaderControl> {
void showSetDecodeFormats() {
// 当前选中的解码格式
final VideoDecodeFormats currentDecodeFormats =
widget.videoDetailCtr!.currentDecodeFormats;
widget.videoDetailCtr!.currentDecodeFormats!;
final VideoItem firstVideo = widget.videoDetailCtr!.firstVideo;
// 当前视频可用的解码格式
final List<FormatItem> videoFormat = videoInfo.supportFormats!;