opt: subtitle & video screenshot (#2364)

This commit is contained in:
My-Responsitories
2026-06-09 02:06:55 +00:00
committed by dom
parent 263a0923d7
commit 658f493f9c
6 changed files with 68 additions and 78 deletions

View File

@@ -802,7 +802,7 @@ abstract final class VideoHttp {
..writeAll(
list.map(
(item) =>
'${item?['sid'] ?? 0}\n${_subtitleTimecode(item['from'])} --> ${_subtitleTimecode(item['to'])}\n${item['content'].trim()}',
'${_subtitleTimecode(item['from'])} --> ${_subtitleTimecode(item['to'])}\n${item['content'].trim()}',
),
'\n\n',
);

View File

@@ -1,4 +1,3 @@
import 'dart:io' show File;
import 'dart:math' show min;
import 'package:PiliPlus/common/style.dart';
@@ -48,12 +47,10 @@ import 'package:PiliPlus/services/download/download_service.dart';
import 'package:PiliPlus/utils/accounts.dart';
import 'package:PiliPlus/utils/connectivity_utils.dart';
import 'package:PiliPlus/utils/extension/context_ext.dart';
import 'package:PiliPlus/utils/extension/file_ext.dart';
import 'package:PiliPlus/utils/extension/iterable_ext.dart';
import 'package:PiliPlus/utils/extension/num_ext.dart';
import 'package:PiliPlus/utils/extension/size_ext.dart';
import 'package:PiliPlus/utils/page_utils.dart';
import 'package:PiliPlus/utils/path_utils.dart';
import 'package:PiliPlus/utils/platform_utils.dart';
import 'package:PiliPlus/utils/storage.dart';
import 'package:PiliPlus/utils/storage_pref.dart';
@@ -68,7 +65,6 @@ import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:hive_ce/hive.dart';
import 'package:media_kit/media_kit.dart' hide Subtitle;
import 'package:path/path.dart' as path;
class VideoDetailController extends GetxController
with GetTickerProviderStateMixin, BlockMixin {
@@ -996,19 +992,8 @@ class VideoDetailController extends GetxController
final sub = subtitles[index - 1];
String subUri = subtitle.id;
File? file;
if (subtitle.isData) {
subUri = path.join(tmpDirPath, '${cid.value}-${sub.lan}.vtt');
file = File(subUri);
if (!file.existsSync()) {
await file.writeAsString(subtitle.id);
if (plPlayerController.videoPlayerController?.disposed == false) {
plPlayerController.videoPlayerController!.release.add(file.tryDel);
} else {
file.tryDel();
return;
}
}
subUri = 'memory://$subUri';
}
await plPlayerController.videoPlayerController?.setSubtitleTrack(
SubtitleTrack(subUri, sub.lanDoc, sub.lan, uri: true),

View File

@@ -341,12 +341,16 @@ class _ReplyPageState extends CommonRichTextPubPageState<ReplyPage> {
final res = await plPlayerController
.plPlayerController
.videoPlayerController
?.screenshot(format: .png);
?.screenshot();
if (res != null) {
final path =
'$tmpDirPath/${Utils.generateRandomString(8)}.png';
await File(path).writeAsBytes(res);
imageList.add(FilePicModel(path: path));
final png = await res.toByteData(format: .png);
if (png != null) {
final path =
'$tmpDirPath/${Utils.generateRandomString(8)}.png';
await File(path).writeAsBytes(png.buffer.asUint8List());
imageList.add(FilePicModel(path: path));
}
res.dispose();
} else {
debugPrint('null screenshot');
}

View File

@@ -27,7 +27,6 @@ import 'package:PiliPlus/plugin/pl_player/utils/fullscreen.dart';
import 'package:PiliPlus/services/service_locator.dart';
import 'package:PiliPlus/utils/accounts.dart';
import 'package:PiliPlus/utils/android/bindings.g.dart';
import 'package:PiliPlus/utils/device_utils.dart';
import 'package:PiliPlus/utils/extension/box_ext.dart';
import 'package:PiliPlus/utils/extension/num_ext.dart';
import 'package:PiliPlus/utils/image_utils.dart';
@@ -1395,50 +1394,52 @@ class PlPlayerController with BlockConfigMixin {
videoShot = await VideoHttp.videoshot(bvid: bvid, cid: cid!);
}
void takeScreenshot() {
Future<void> takeScreenshot() async {
SmartDialog.showToast('截图中');
videoPlayerController?.screenshot(format: .png).then((value) {
if (value != null) {
SmartDialog.showToast('点击弹窗保存截图');
showDialog(
context: Get.context!,
builder: (context) => GestureDetector(
onTap: () {
Get.back();
final image = await videoPlayerController?.screenshot();
if (image != null) {
SmartDialog.showToast('点击弹窗保存截图');
showDialog(
context: Get.context!,
builder: (context) => GestureDetector(
onTap: () async {
Get.back();
final bytes = await image.toByteData(format: .png);
if (bytes != null) {
ImageUtils.saveByteImg(
bytes: value,
bytes: bytes.buffer.asUint8List(),
fileName: 'screenshot_${ImageUtils.time}',
);
},
child: Align(
alignment: .centerRight,
child: Padding(
padding: const .only(right: 12),
child: ConstrainedBox(
constraints: BoxConstraints(
maxWidth: min(DeviceUtils.size.width / 3, 350),
}
},
child: Align(
alignment: .centerRight,
child: Padding(
padding: const .only(right: 12),
child: ConstrainedBox(
constraints: BoxConstraints(
maxWidth: min(MediaQuery.widthOf(context) / 3, 350),
),
child: DecoratedBox(
decoration: BoxDecoration(
border: .all(
width: 5,
color: ThemeUtils.theme.colorScheme.surface,
),
),
child: DecoratedBox(
decoration: BoxDecoration(
border: .all(
width: 5,
color: ThemeUtils.theme.colorScheme.surface,
),
),
child: Padding(
padding: const .all(5),
child: Image.memory(value),
),
child: Padding(
padding: const .all(5),
child: RawImage(image: image),
),
),
),
),
),
);
} else {
SmartDialog.showToast('截图失败');
}
});
),
).whenComplete(image.dispose);
} else {
SmartDialog.showToast('截图失败');
}
}
void onPopInvokedWithResult(bool didPop, Object? result) {

View File

@@ -1077,8 +1077,8 @@ packages:
description:
path: media_kit
ref: "version_1.2.5"
resolved-ref: "4660bd0743d5643d49093af70f8bcd404f787f9c"
url: "https://github.com/bggRGjQaUbCoE/media-kit.git"
resolved-ref: e6c3481025959a23c259aa6072a28cebaa1c0fcc
url: "https://github.com/My-Responsitories/media-kit.git"
source: git
version: "1.1.11"
media_kit_libs_android_video:
@@ -1086,8 +1086,8 @@ packages:
description:
path: "libs/android/media_kit_libs_android_video"
ref: "version_1.2.5"
resolved-ref: "4660bd0743d5643d49093af70f8bcd404f787f9c"
url: "https://github.com/bggRGjQaUbCoE/media-kit.git"
resolved-ref: e6c3481025959a23c259aa6072a28cebaa1c0fcc
url: "https://github.com/My-Responsitories/media-kit.git"
source: git
version: "1.3.7"
media_kit_libs_ios_video:
@@ -1095,8 +1095,8 @@ packages:
description:
path: "libs/ios/media_kit_libs_ios_video"
ref: "version_1.2.5"
resolved-ref: "4660bd0743d5643d49093af70f8bcd404f787f9c"
url: "https://github.com/bggRGjQaUbCoE/media-kit.git"
resolved-ref: e6c3481025959a23c259aa6072a28cebaa1c0fcc
url: "https://github.com/My-Responsitories/media-kit.git"
source: git
version: "1.1.4"
media_kit_libs_linux:
@@ -1120,8 +1120,8 @@ packages:
description:
path: "libs/universal/media_kit_libs_video"
ref: "version_1.2.5"
resolved-ref: "4660bd0743d5643d49093af70f8bcd404f787f9c"
url: "https://github.com/bggRGjQaUbCoE/media-kit.git"
resolved-ref: e6c3481025959a23c259aa6072a28cebaa1c0fcc
url: "https://github.com/My-Responsitories/media-kit.git"
source: git
version: "1.0.5"
media_kit_libs_windows_video:
@@ -1129,8 +1129,8 @@ packages:
description:
path: "libs/windows/media_kit_libs_windows_video"
ref: "version_1.2.5"
resolved-ref: "4660bd0743d5643d49093af70f8bcd404f787f9c"
url: "https://github.com/bggRGjQaUbCoE/media-kit.git"
resolved-ref: e6c3481025959a23c259aa6072a28cebaa1c0fcc
url: "https://github.com/My-Responsitories/media-kit.git"
source: git
version: "1.0.10"
media_kit_native_event_loop:
@@ -1138,8 +1138,8 @@ packages:
description:
path: media_kit_native_event_loop
ref: "version_1.2.5"
resolved-ref: "4660bd0743d5643d49093af70f8bcd404f787f9c"
url: "https://github.com/bggRGjQaUbCoE/media-kit.git"
resolved-ref: e6c3481025959a23c259aa6072a28cebaa1c0fcc
url: "https://github.com/My-Responsitories/media-kit.git"
source: git
version: "1.0.9"
media_kit_video:
@@ -1147,8 +1147,8 @@ packages:
description:
path: media_kit_video
ref: "version_1.2.5"
resolved-ref: "4660bd0743d5643d49093af70f8bcd404f787f9c"
url: "https://github.com/bggRGjQaUbCoE/media-kit.git"
resolved-ref: e6c3481025959a23c259aa6072a28cebaa1c0fcc
url: "https://github.com/My-Responsitories/media-kit.git"
source: git
version: "1.2.5"
menu_base:

View File

@@ -195,37 +195,37 @@ dependency_overrides:
flutter_volume_controller: ^2.0.0
media_kit:
git:
url: https://github.com/bggRGjQaUbCoE/media-kit.git
url: https://github.com/My-Responsitories/media-kit.git
path: media_kit
ref: version_1.2.5
media_kit_libs_android_video:
git:
url: https://github.com/bggRGjQaUbCoE/media-kit.git
url: https://github.com/My-Responsitories/media-kit.git
path: libs/android/media_kit_libs_android_video
ref: version_1.2.5
media_kit_libs_ios_video:
git:
url: https://github.com/bggRGjQaUbCoE/media-kit.git
url: https://github.com/My-Responsitories/media-kit.git
path: libs/ios/media_kit_libs_ios_video
ref: version_1.2.5
media_kit_libs_video:
git:
url: https://github.com/bggRGjQaUbCoE/media-kit.git
url: https://github.com/My-Responsitories/media-kit.git
path: libs/universal/media_kit_libs_video
ref: version_1.2.5
media_kit_libs_windows_video:
git:
url: https://github.com/bggRGjQaUbCoE/media-kit.git
url: https://github.com/My-Responsitories/media-kit.git
path: libs/windows/media_kit_libs_windows_video
ref: version_1.2.5
media_kit_native_event_loop:
git:
url: https://github.com/bggRGjQaUbCoE/media-kit.git
url: https://github.com/My-Responsitories/media-kit.git
path: media_kit_native_event_loop
ref: version_1.2.5
media_kit_video:
git:
url: https://github.com/bggRGjQaUbCoE/media-kit.git
url: https://github.com/My-Responsitories/media-kit.git
path: media_kit_video
ref: version_1.2.5
screen_brightness_android: