fix: 没有audio 资源的视频异常

This commit is contained in:
guozhigq
2023-08-20 15:47:59 +08:00
parent 83341cd62b
commit 50a5653516
2 changed files with 17 additions and 14 deletions

View File

@ -38,7 +38,7 @@ class VideoDetailController extends GetxController
/// 播放器配置 画质 音质 解码格式 /// 播放器配置 画质 音质 解码格式
late VideoQuality currentVideoQa; late VideoQuality currentVideoQa;
late AudioQuality currentAudioQa; AudioQuality? currentAudioQa;
late VideoDecodeFormats currentDecodeFormats; late VideoDecodeFormats currentDecodeFormats;
// PlPlayerController plPlayerController = PlPlayerController(); // PlPlayerController plPlayerController = PlPlayerController();
// 是否开始自动播放 存在多p的情况下第二p需要为true // 是否开始自动播放 存在多p的情况下第二p需要为true
@ -142,9 +142,11 @@ class VideoDetailController extends GetxController
videoUrl = firstVideo.baseUrl!; videoUrl = firstVideo.baseUrl!;
/// 根据currentAudioQa 重新设置audioUrl /// 根据currentAudioQa 重新设置audioUrl
AudioItem firstAudio = if (currentAudioQa != null) {
data.dash!.audio!.firstWhere((i) => i.id == currentAudioQa.code); AudioItem firstAudio =
audioUrl = firstAudio.baseUrl ?? ''; data.dash!.audio!.firstWhere((i) => i.id == currentAudioQa!.code);
audioUrl = firstAudio.baseUrl ?? '';
}
playerInit(); playerInit();
} }

View File

@ -120,15 +120,16 @@ class _HeaderControlState extends State<HeaderControl> {
'当前画质 ${widget.videoDetailCtr!.currentVideoQa.description}', '当前画质 ${widget.videoDetailCtr!.currentVideoQa.description}',
style: subTitleStyle), style: subTitleStyle),
), ),
ListTile( if (widget.videoDetailCtr!.currentAudioQa != null)
onTap: () => {Get.back(), showSetAudioQa()}, ListTile(
dense: true, onTap: () => {Get.back(), showSetAudioQa()},
leading: const Icon(Icons.album_outlined, size: 20), dense: true,
title: Text('选择音质', style: titleStyle), leading: const Icon(Icons.album_outlined, size: 20),
subtitle: Text( title: Text('选择音质', style: titleStyle),
'当前音质 ${widget.videoDetailCtr!.currentAudioQa.description}', subtitle: Text(
style: subTitleStyle), '当前音质 ${widget.videoDetailCtr!.currentAudioQa!.description}',
), style: subTitleStyle),
),
ListTile( ListTile(
onTap: () => {Get.back(), showSetDecodeFormats()}, onTap: () => {Get.back(), showSetDecodeFormats()},
dense: true, dense: true,
@ -319,7 +320,7 @@ class _HeaderControlState extends State<HeaderControl> {
/// 选择音质 /// 选择音质
void showSetAudioQa() { void showSetAudioQa() {
AudioQuality currentAudioQa = widget.videoDetailCtr!.currentAudioQa; AudioQuality currentAudioQa = widget.videoDetailCtr!.currentAudioQa!;
List<AudioItem> audio = videoInfo.dash!.audio!; List<AudioItem> audio = videoInfo.dash!.audio!;
showModalBottomSheet( showModalBottomSheet(