mod: 默认缓冲区调小;当前解码格式查找+兜底

This commit is contained in:
orz12
2024-07-07 15:15:53 +08:00
parent 2522831cfc
commit 391c11831d
4 changed files with 32 additions and 9 deletions

View File

@@ -178,6 +178,25 @@ class VideoItem {
codecid = json['codecid']; codecid = json['codecid'];
quality = VideoQuality.values.firstWhere((i) => i.code == json['id']); quality = VideoQuality.values.firstWhere((i) => i.code == json['id']);
} }
Map<String, dynamic> toJson() {
Map<String, dynamic> data = <String, dynamic>{};
data['id'] = id;
data['baseUrl'] = baseUrl;
data['backupUrl'] = backupUrl;
data['bandWidth'] = bandWidth;
data['mime_type'] = mimeType;
data['codecs'] = codecs;
data['width'] = width;
data['height'] = height;
data['frameRate'] = frameRate;
data['sar'] = sar;
data['startWithSap'] = startWithSap;
data['segmentBase'] = segmentBase;
data['codecid'] = codecid;
data['quality'] = quality;
return data;
}
} }
class AudioItem { class AudioItem {

View File

@@ -207,7 +207,7 @@ class _VideoSettingState extends State<VideoSetting> {
const SetSwitchItem( const SetSwitchItem(
title: '扩大缓冲区', title: '扩大缓冲区',
leading: Icon(Icons.storage_outlined), leading: Icon(Icons.storage_outlined),
subTitle: '默认缓冲区为视频5MB/直播32MB开启后为32MB/64MB加载时间变长', subTitle: '默认缓冲区为视频3MB/直播16MB开启后为32MB/64MB加载时间变长',
setKey: SettingBoxKey.expandBuffer, setKey: SettingBoxKey.expandBuffer,
defaultVal: false, defaultVal: false,
), ),

View File

@@ -206,7 +206,9 @@ class VideoDetailController extends GetxController
} }
if (flag == 1) { if (flag == 1) {
//currentDecodeFormats //currentDecodeFormats
firstVideo = videoList.first; firstVideo = videoList.firstWhere(
(i) => i.codecs!.startsWith(currentDecodeFormats.code),
orElse: () => videoList.first);
} else { } else {
if (currentVideoQa == VideoQuality.dolbyVision) { if (currentVideoQa == VideoQuality.dolbyVision) {
currentDecodeFormats = currentDecodeFormats =
@@ -217,12 +219,14 @@ class VideoDetailController extends GetxController
currentDecodeFormats = defaultDecodeFormats; currentDecodeFormats = defaultDecodeFormats;
firstVideo = videoList.firstWhere( firstVideo = videoList.firstWhere(
(i) => i.codecs!.startsWith(defaultDecodeFormats.code), (i) => i.codecs!.startsWith(defaultDecodeFormats.code),
orElse: () => videoList.first,
); );
} else if (flag == 4) { } else if (flag == 4) {
//secondDecodeFormats //secondDecodeFormats
currentDecodeFormats = secondDecodeFormats; currentDecodeFormats = secondDecodeFormats;
firstVideo = videoList.firstWhere( firstVideo = videoList.firstWhere(
(i) => i.codecs!.startsWith(secondDecodeFormats.code), (i) => i.codecs!.startsWith(secondDecodeFormats.code),
orElse: () => videoList.first,
); );
} else if (flag == 0) { } else if (flag == 0) {
currentDecodeFormats = currentDecodeFormats =
@@ -312,11 +316,10 @@ class VideoDetailController extends GetxController
defaultST = Duration.zero; defaultST = Duration.zero;
// 实际为FLV/MP4格式但已被淘汰这里仅做兜底处理 // 实际为FLV/MP4格式但已被淘汰这里仅做兜底处理
firstVideo = VideoItem( firstVideo = VideoItem(
id: data.quality!, id: data.quality!,
baseUrl: videoUrl, baseUrl: videoUrl,
codecs: 'avc1', codecs: 'avc1',
quality: VideoQualityCode.fromCode(data.quality!)! quality: VideoQualityCode.fromCode(data.quality!)!);
);
currentDecodeFormats = VideoDecodeFormatsCode.fromString('avc1')!; currentDecodeFormats = VideoDecodeFormatsCode.fromString('avc1')!;
currentVideoQa = VideoQualityCode.fromCode(data.quality!)!; currentVideoQa = VideoQualityCode.fromCode(data.quality!)!;
if (autoPlay.value) { if (autoPlay.value) {
@@ -390,7 +393,8 @@ class VideoDetailController extends GetxController
late AudioItem? firstAudio; late AudioItem? firstAudio;
final List<AudioItem> audiosList = data.dash!.audio!; final List<AudioItem> audiosList = data.dash!.audio!;
if (data.dash!.dolby?.audio != null && data.dash!.dolby!.audio!.isNotEmpty) { if (data.dash!.dolby?.audio != null &&
data.dash!.dolby!.audio!.isNotEmpty) {
// 杜比 // 杜比
audiosList.insert(0, data.dash!.dolby!.audio!.first); audiosList.insert(0, data.dash!.dolby!.audio!.first);
} }

View File

@@ -505,7 +505,7 @@ class PlPlayerController {
int bufferSize = int bufferSize =
setting.get(SettingBoxKey.expandBuffer, defaultValue: false) setting.get(SettingBoxKey.expandBuffer, defaultValue: false)
? (videoType.value == 'live' ? 64 * 1024 * 1024 : 32 * 1024 * 1024) ? (videoType.value == 'live' ? 64 * 1024 * 1024 : 32 * 1024 * 1024)
: (videoType.value == 'live' ? 32 * 1024 * 1024 : 5 * 1024 * 1024); : (videoType.value == 'live' ? 16 * 1024 * 1024 : 3 * 1024 * 1024);
Player player = _videoPlayerController ?? Player player = _videoPlayerController ??
Player( Player(
configuration: PlayerConfiguration( configuration: PlayerConfiguration(