feat: ai translate

Closes #1285

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-09-20 11:46:38 +08:00
parent 9b171e04be
commit 0745d83e4b
10 changed files with 155 additions and 20 deletions

View File

@@ -29,6 +29,7 @@ class BottomControl extends StatelessWidget {
@override
Widget build(BuildContext context) {
final isFullScreen = plPlayerController.isFullScreen.value;
return AppBar(
backgroundColor: Colors.transparent,
foregroundColor: Colors.white,
@@ -40,6 +41,7 @@ class BottomControl extends StatelessWidget {
PlayOrPauseButton(plPlayerController: plPlayerController),
ComBtn(
height: 30,
tooltip: '刷新',
icon: const Icon(
Icons.refresh,
size: 18,
@@ -50,6 +52,7 @@ class BottomControl extends StatelessWidget {
const Spacer(),
ComBtn(
height: 30,
tooltip: '屏蔽',
icon: const Icon(
size: 18,
Icons.block,
@@ -74,6 +77,7 @@ class BottomControl extends StatelessWidget {
final enableShowLiveDanmaku =
plPlayerController.enableShowLiveDanmaku.value;
return ComBtn(
tooltip: "${enableShowLiveDanmaku ? '关闭' : '开启'}弹幕",
icon: enableShowLiveDanmaku
? const Icon(
size: 18,
@@ -100,6 +104,7 @@ class BottomControl extends StatelessWidget {
),
Obx(
() => PopupMenuButton<VideoFitType>(
tooltip: '画面比例',
initialValue: plPlayerController.videoFit.value,
color: Colors.black.withValues(alpha: 0.8),
itemBuilder: (context) {
@@ -132,6 +137,7 @@ class BottomControl extends StatelessWidget {
),
Obx(
() => PopupMenuButton<int>(
tooltip: '画质',
padding: EdgeInsets.zero,
initialValue: liveRoomCtr.currentQn,
color: Colors.black.withValues(alpha: 0.8),
@@ -165,22 +171,20 @@ class BottomControl extends StatelessWidget {
),
ComBtn(
height: 30,
icon: plPlayerController.isFullScreen.value
tooltip: isFullScreen ? '退出全屏' : '全屏',
icon: isFullScreen
? const Icon(
Icons.fullscreen_exit,
semanticLabel: '退出全屏',
size: 24,
color: Colors.white,
)
: const Icon(
Icons.fullscreen,
semanticLabel: '全屏',
size: 24,
color: Colors.white,
),
onTap: () => plPlayerController.triggerFullScreen(
status: !plPlayerController.isFullScreen.value,
),
onTap: () =>
plPlayerController.triggerFullScreen(status: !isFullScreen),
),
],
),

View File

@@ -72,11 +72,13 @@ class LiveHeaderControl extends StatelessWidget {
children: [
if (isFullScreen)
ComBtn(
tooltip: '返回',
icon: const Icon(FontAwesomeIcons.arrowLeft, size: 15),
onTap: () => plPlayerController.triggerFullScreen(status: false),
),
child,
ComBtn(
tooltip: '发弹幕',
icon: const Icon(
size: 18,
Icons.comment_outlined,
@@ -88,6 +90,7 @@ class LiveHeaderControl extends StatelessWidget {
() {
final onlyPlayAudio = plPlayerController.onlyPlayAudio.value;
return ComBtn(
tooltip: '仅播放音频',
onTap: () {
plPlayerController.onlyPlayAudio.value = !onlyPlayAudio;
onPlayAudio();
@@ -108,6 +111,7 @@ class LiveHeaderControl extends StatelessWidget {
),
if (Platform.isAndroid)
ComBtn(
tooltip: '画中画',
onTap: () async {
try {
var floating = Floating();
@@ -130,6 +134,7 @@ class LiveHeaderControl extends StatelessWidget {
),
),
ComBtn(
tooltip: '定时关闭',
onTap: () => PageUtils.scheduleExit(
context,
plPlayerController.isFullScreen.value,

View File

@@ -247,13 +247,15 @@ class VideoDetailController extends GetxController
imageStatus = false;
}
final isLoginVideo = Accounts.get(AccountType.video).isLogin;
@override
void onInit() {
super.onInit();
args = Get.arguments;
videoType = args['videoType'];
if (videoType == VideoType.pgc) {
if (!Accounts.get(AccountType.video).isLogin) {
if (!isLoginVideo) {
_actualVideoType = VideoType.ugc;
}
} else if (args['pgcApi'] == true) {
@@ -1112,6 +1114,17 @@ class VideoDetailController extends GetxController
bool isQuerying = false;
final Rx<List<LanguageItem>?> languages = Rx<List<LanguageItem>?>(null);
final Rx<String?> currLang = Rx(null);
void setLanguage(String language) {
if (!isLoginVideo) {
SmartDialog.showToast('账号未登录');
return;
}
currLang.value = language;
queryVideoUrl(defaultST: playedTime);
}
// 视频链接
Future<void> queryVideoUrl({
Duration? defaultST,
@@ -1142,11 +1155,15 @@ class VideoDetailController extends GetxController
seasonId: seasonId,
tryLook: plPlayerController.tryLook,
videoType: _actualVideoType ?? videoType,
language: currLang.value,
);
if (result.isSuccess) {
data = result.data;
languages.value = data.language?.items;
currLang.value = data.curLanguage;
if (data.acceptDesc?.contains('试看') == true) {
SmartDialog.showToast(
'该视频为专属视频,仅提供试看',
@@ -1564,6 +1581,10 @@ class VideoDetailController extends GetxController
videoUrl = null;
audioUrl = null;
// language
languages.value = null;
currLang.value = null;
if (scrollRatio.value != 0) {
scrollRatio.refresh();
}