opt: 字幕按钮显隐逻辑

This commit is contained in:
guozhigq
2024-06-30 13:02:50 +08:00
parent 9f1b74b7e2
commit a19129c596
2 changed files with 38 additions and 25 deletions

View File

@ -141,13 +141,7 @@ class VideoDetailController extends GetxController
if (Platform.isAndroid) {
floating = Floating();
}
headerControl = HeaderControl(
controller: plPlayerController,
videoDetailCtr: this,
floating: floating,
bvid: bvid,
videoType: videoType,
);
// CDN优化
enableCDN = setting.get(SettingBoxKey.enableCDN, defaultValue: true);
// 预设的画质
@ -158,7 +152,18 @@ class VideoDetailController extends GetxController
defaultAudioQa = setting.get(SettingBoxKey.defaultAudioQa,
defaultValue: AudioQuality.hiRes.code);
oid.value = IdUtils.bv2av(Get.parameters['bvid']!);
getSubtitle();
getSubtitle().then(
(subtitles) {
headerControl = HeaderControl(
controller: plPlayerController,
videoDetailCtr: this,
floating: floating,
bvid: bvid,
videoType: videoType,
showSubtitleBtn: subtitles.isNotEmpty,
);
},
);
}
showReplyReplyPanel(oid, fRpid, firstFloor) {
@ -432,17 +437,22 @@ class VideoDetailController extends GetxController
if (result['status']) {
if (result['data'].subtitles.isNotEmpty) {
subtitles = result['data'].subtitles;
if (subtitles.isNotEmpty) {
for (var i in subtitles) {
final Map<String, dynamic> res = await VideoHttp.getSubtitleContent(
i.subtitleUrl,
);
i.content = res['content'];
i.body = res['body'];
}
}
getDanmaku(subtitles);
}
return subtitles;
}
}
// 获取弹幕
Future getDanmaku(List subtitles) async {
if (subtitles.isNotEmpty) {
for (var i in subtitles) {
final Map<String, dynamic> res = await VideoHttp.getSubtitleContent(
i.subtitleUrl,
);
i.content = res['content'];
i.body = res['body'];
}
return result['data'];
}
}

View File

@ -30,6 +30,7 @@ class HeaderControl extends StatefulWidget implements PreferredSizeWidget {
this.floating,
this.bvid,
this.videoType,
this.showSubtitleBtn,
super.key,
});
final PlPlayerController? controller;
@ -37,6 +38,7 @@ class HeaderControl extends StatefulWidget implements PreferredSizeWidget {
final Floating? floating;
final String? bvid;
final SearchType? videoType;
final bool? showSubtitleBtn;
@override
State<HeaderControl> createState() => _HeaderControlState();
@ -1327,14 +1329,15 @@ class _HeaderControlState extends State<HeaderControl> {
],
/// 字幕
ComBtn(
icon: const Icon(
Icons.closed_caption_off,
size: 22,
color: Colors.white,
if (widget.showSubtitleBtn!)
ComBtn(
icon: const Icon(
Icons.closed_caption_off,
size: 22,
color: Colors.white,
),
fuc: () => showSubtitleDialog(),
),
fuc: () => showSubtitleDialog(),
),
SizedBox(width: buttonSpace),
Obx(
() => SizedBox(