mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-06-10 21:11:27 +08:00
opt: subtitle & video screenshot (#2364)
This commit is contained in:
committed by
GitHub
parent
46d9f8ab1c
commit
fe15024384
@@ -851,7 +851,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',
|
||||
);
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'dart:math' show min;
|
||||
import 'dart:ui';
|
||||
|
||||
@@ -54,12 +53,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';
|
||||
@@ -75,7 +72,6 @@ import 'package:flutter_volume_controller/flutter_volume_controller.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 {
|
||||
@@ -1081,19 +1077,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),
|
||||
|
||||
@@ -350,12 +350,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');
|
||||
}
|
||||
|
||||
@@ -1724,50 +1724,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 {
|
||||
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: Alignment.centerRight,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(right: 12),
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(
|
||||
maxWidth: min(DeviceUtils.size.width / 3, 350),
|
||||
}
|
||||
Get.back();
|
||||
},
|
||||
child: Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(right: 12),
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(
|
||||
maxWidth: min(MediaQuery.widthOf(context) / 3, 350),
|
||||
),
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(
|
||||
width: 5,
|
||||
color: ThemeUtils.theme.colorScheme.surface,
|
||||
),
|
||||
),
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(
|
||||
width: 5,
|
||||
color: ThemeUtils.theme.colorScheme.surface,
|
||||
),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(5),
|
||||
child: Image.memory(value),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(5),
|
||||
child: RawImage(image: image),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
SmartDialog.showToast('截图失败');
|
||||
}
|
||||
});
|
||||
),
|
||||
).whenComplete(image.dispose);
|
||||
} else {
|
||||
SmartDialog.showToast('截图失败');
|
||||
}
|
||||
}
|
||||
|
||||
void onPopInvokedWithResult(bool didPop, Object? result) {
|
||||
|
||||
28
pubspec.lock
28
pubspec.lock
@@ -1115,8 +1115,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:
|
||||
@@ -1124,8 +1124,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:
|
||||
@@ -1133,8 +1133,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:
|
||||
@@ -1158,8 +1158,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:
|
||||
@@ -1167,8 +1167,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:
|
||||
@@ -1176,8 +1176,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:
|
||||
@@ -1185,8 +1185,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:
|
||||
|
||||
14
pubspec.yaml
14
pubspec.yaml
@@ -187,37 +187,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:
|
||||
|
||||
Reference in New Issue
Block a user