From a928c575efc6d46a5d6a7e21ee772269cff4473f Mon Sep 17 00:00:00 2001 From: guozhigq Date: Sat, 26 Aug 2023 15:23:22 +0800 Subject: [PATCH] fix: supportFormats codecs match dvh1 --- lib/models/video/play/quality.dart | 13 ++----- lib/pages/video/detail/controller.dart | 37 ++++++++++++++----- .../video/detail/widgets/header_control.dart | 5 ++- 3 files changed, 34 insertions(+), 21 deletions(-) diff --git a/lib/models/video/play/quality.dart b/lib/models/video/play/quality.dart index 4d9d7d6e..6cae84cc 100644 --- a/lib/models/video/play/quality.dart +++ b/lib/models/video/play/quality.dart @@ -93,26 +93,19 @@ extension AudioQualityDesc on AudioQuality { } enum VideoDecodeFormats { + DVH1, AV1, HEVC, AVC, } extension VideoDecodeFormatsDesc on VideoDecodeFormats { - static final List _descList = [ - 'AV1', - 'HEVC', - 'AVC', - ]; + static final List _descList = ['DVH1', 'AV1', 'HEVC', 'AVC']; get description => _descList[index]; } extension VideoDecodeFormatsCode on VideoDecodeFormats { - static final List _codeList = [ - 'av01', - 'hev1', - 'avc1', - ]; + static final List _codeList = ['dvh1', 'av01', 'hev1', 'avc1']; get code => _codeList[index]; static VideoDecodeFormats? fromCode(String code) { diff --git a/lib/pages/video/detail/controller.dart b/lib/pages/video/detail/controller.dart index 3f4bfc6f..e4fd89dc 100644 --- a/lib/pages/video/detail/controller.dart +++ b/lib/pages/video/detail/controller.dart @@ -140,8 +140,17 @@ class VideoDetailController extends GetxController /// 根据currentVideoQa和currentDecodeFormats 重新设置videoUrl List videoList = data.dash!.video!.where((i) => i.id == currentVideoQa.code).toList(); - firstVideo = videoList - .firstWhere((i) => i.codecs!.startsWith(currentDecodeFormats.code)); + try { + firstVideo = videoList + .firstWhere((i) => i.codecs!.startsWith(currentDecodeFormats.code)); + } catch (_) { + // 当前格式不可用 + currentDecodeFormats = VideoDecodeFormatsCode.fromString(setting.get( + SettingBoxKey.defaultDecode, + defaultValue: VideoDecodeFormats.values.last.code))!; + firstVideo = videoList + .firstWhere((i) => i.codecs!.startsWith(currentDecodeFormats.code)); + } videoUrl = firstVideo.baseUrl!; /// 根据currentAudioQa 重新设置audioUrl @@ -243,17 +252,25 @@ class VideoDetailController extends GetxController defaultValue: VideoDecodeFormats.values.last.code))!; try { // 当前视频没有对应格式返回第一个 - currentDecodeFormats = - supportDecodeFormats.contains(supportDecodeFormats) - ? supportDecodeFormats - : supportDecodeFormats.first; - } catch (_) {} + currentDecodeFormats = supportDecodeFormats + .contains(currentDecodeFormats) + ? currentDecodeFormats + : VideoDecodeFormatsCode.fromString(supportDecodeFormats.first)!; + } catch (e) { + print(e); + } /// 取出符合当前解码格式的videoItem - firstVideo = videosList - .firstWhere((e) => e.codecs!.startsWith(currentDecodeFormats.code)); + try { + firstVideo = videosList.firstWhere( + (e) => e.codecs!.startsWith(currentDecodeFormats.code)); + } catch (_) { + firstVideo = videosList.first; + } videoUrl = firstVideo.baseUrl!; - } catch (_) {} + } catch (err) { + print(err); + } /// 优先顺序 设置中指定质量 -> 当前可选的最高质量 late AudioItem firstAudio; diff --git a/lib/pages/video/detail/widgets/header_control.dart b/lib/pages/video/detail/widgets/header_control.dart index 6e5e7665..77619043 100644 --- a/lib/pages/video/detail/widgets/header_control.dart +++ b/lib/pages/video/detail/widgets/header_control.dart @@ -387,9 +387,12 @@ class _HeaderControlState extends State { // 当前选中的解码格式 VideoDecodeFormats currentDecodeFormats = widget.videoDetailCtr!.currentDecodeFormats; + VideoItem firstVideo = widget.videoDetailCtr!.firstVideo; // 当前视频可用的解码格式 List videoFormat = videoInfo.supportFormats!; - List list = videoFormat.first.codecs!; + List list = videoFormat + .firstWhere((e) => e.quality == firstVideo.quality!.code) + .codecs!; showModalBottomSheet( context: context,