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( ..writeAll(
list.map( list.map(
(item) => (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', '\n\n',
); );

View File

@@ -1,4 +1,3 @@
import 'dart:io' show File;
import 'dart:math' show min; import 'dart:math' show min;
import 'package:PiliPlus/common/style.dart'; 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/accounts.dart';
import 'package:PiliPlus/utils/connectivity_utils.dart'; import 'package:PiliPlus/utils/connectivity_utils.dart';
import 'package:PiliPlus/utils/extension/context_ext.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/iterable_ext.dart';
import 'package:PiliPlus/utils/extension/num_ext.dart'; import 'package:PiliPlus/utils/extension/num_ext.dart';
import 'package:PiliPlus/utils/extension/size_ext.dart'; import 'package:PiliPlus/utils/extension/size_ext.dart';
import 'package:PiliPlus/utils/page_utils.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/platform_utils.dart';
import 'package:PiliPlus/utils/storage.dart'; import 'package:PiliPlus/utils/storage.dart';
import 'package:PiliPlus/utils/storage_pref.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:get/get.dart';
import 'package:hive_ce/hive.dart'; import 'package:hive_ce/hive.dart';
import 'package:media_kit/media_kit.dart' hide Subtitle; import 'package:media_kit/media_kit.dart' hide Subtitle;
import 'package:path/path.dart' as path;
class VideoDetailController extends GetxController class VideoDetailController extends GetxController
with GetTickerProviderStateMixin, BlockMixin { with GetTickerProviderStateMixin, BlockMixin {
@@ -996,19 +992,8 @@ class VideoDetailController extends GetxController
final sub = subtitles[index - 1]; final sub = subtitles[index - 1];
String subUri = subtitle.id; String subUri = subtitle.id;
File? file;
if (subtitle.isData) { if (subtitle.isData) {
subUri = path.join(tmpDirPath, '${cid.value}-${sub.lan}.vtt'); subUri = 'memory://$subUri';
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;
}
}
} }
await plPlayerController.videoPlayerController?.setSubtitleTrack( await plPlayerController.videoPlayerController?.setSubtitleTrack(
SubtitleTrack(subUri, sub.lanDoc, sub.lan, uri: true), SubtitleTrack(subUri, sub.lanDoc, sub.lan, uri: true),

View File

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

View File

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

View File

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