fix: supportFormats codecs match dvh1

This commit is contained in:
guozhigq
2023-08-26 15:23:22 +08:00
parent a0e51c86fc
commit a928c575ef
3 changed files with 34 additions and 21 deletions

View File

@ -93,26 +93,19 @@ extension AudioQualityDesc on AudioQuality {
} }
enum VideoDecodeFormats { enum VideoDecodeFormats {
DVH1,
AV1, AV1,
HEVC, HEVC,
AVC, AVC,
} }
extension VideoDecodeFormatsDesc on VideoDecodeFormats { extension VideoDecodeFormatsDesc on VideoDecodeFormats {
static final List<String> _descList = [ static final List<String> _descList = ['DVH1', 'AV1', 'HEVC', 'AVC'];
'AV1',
'HEVC',
'AVC',
];
get description => _descList[index]; get description => _descList[index];
} }
extension VideoDecodeFormatsCode on VideoDecodeFormats { extension VideoDecodeFormatsCode on VideoDecodeFormats {
static final List<String> _codeList = [ static final List<String> _codeList = ['dvh1', 'av01', 'hev1', 'avc1'];
'av01',
'hev1',
'avc1',
];
get code => _codeList[index]; get code => _codeList[index];
static VideoDecodeFormats? fromCode(String code) { static VideoDecodeFormats? fromCode(String code) {

View File

@ -140,8 +140,17 @@ class VideoDetailController extends GetxController
/// 根据currentVideoQa和currentDecodeFormats 重新设置videoUrl /// 根据currentVideoQa和currentDecodeFormats 重新设置videoUrl
List<VideoItem> videoList = List<VideoItem> videoList =
data.dash!.video!.where((i) => i.id == currentVideoQa.code).toList(); data.dash!.video!.where((i) => i.id == currentVideoQa.code).toList();
firstVideo = videoList try {
.firstWhere((i) => i.codecs!.startsWith(currentDecodeFormats.code)); 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!; videoUrl = firstVideo.baseUrl!;
/// 根据currentAudioQa 重新设置audioUrl /// 根据currentAudioQa 重新设置audioUrl
@ -243,17 +252,25 @@ class VideoDetailController extends GetxController
defaultValue: VideoDecodeFormats.values.last.code))!; defaultValue: VideoDecodeFormats.values.last.code))!;
try { try {
// 当前视频没有对应格式返回第一个 // 当前视频没有对应格式返回第一个
currentDecodeFormats = currentDecodeFormats = supportDecodeFormats
supportDecodeFormats.contains(supportDecodeFormats) .contains(currentDecodeFormats)
? supportDecodeFormats ? currentDecodeFormats
: supportDecodeFormats.first; : VideoDecodeFormatsCode.fromString(supportDecodeFormats.first)!;
} catch (_) {} } catch (e) {
print(e);
}
/// 取出符合当前解码格式的videoItem /// 取出符合当前解码格式的videoItem
firstVideo = videosList try {
.firstWhere((e) => e.codecs!.startsWith(currentDecodeFormats.code)); firstVideo = videosList.firstWhere(
(e) => e.codecs!.startsWith(currentDecodeFormats.code));
} catch (_) {
firstVideo = videosList.first;
}
videoUrl = firstVideo.baseUrl!; videoUrl = firstVideo.baseUrl!;
} catch (_) {} } catch (err) {
print(err);
}
/// 优先顺序 设置中指定质量 -> 当前可选的最高质量 /// 优先顺序 设置中指定质量 -> 当前可选的最高质量
late AudioItem firstAudio; late AudioItem firstAudio;

View File

@ -387,9 +387,12 @@ class _HeaderControlState extends State<HeaderControl> {
// 当前选中的解码格式 // 当前选中的解码格式
VideoDecodeFormats currentDecodeFormats = VideoDecodeFormats currentDecodeFormats =
widget.videoDetailCtr!.currentDecodeFormats; widget.videoDetailCtr!.currentDecodeFormats;
VideoItem firstVideo = widget.videoDetailCtr!.firstVideo;
// 当前视频可用的解码格式 // 当前视频可用的解码格式
List<FormatItem> videoFormat = videoInfo.supportFormats!; List<FormatItem> videoFormat = videoInfo.supportFormats!;
List list = videoFormat.first.codecs!; List list = videoFormat
.firstWhere((e) => e.quality == firstVideo.quality!.code)
.codecs!;
showModalBottomSheet( showModalBottomSheet(
context: context, context: context,