mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-06-02 00:58:19 +08:00
@@ -668,51 +668,49 @@ class HeaderControlState extends State<HeaderControl>
|
||||
onTap: () async {
|
||||
Get.back();
|
||||
try {
|
||||
final result = await FilePicker.pickFiles(
|
||||
final result = await FilePicker.pickFile(
|
||||
type: .custom,
|
||||
allowedExtensions: const ['json', 'vtt', 'srt', 'ass'],
|
||||
);
|
||||
if (result != null) {
|
||||
final file = result.files.single;
|
||||
final file = result.xFile;
|
||||
final path = file.path;
|
||||
if (path != null) {
|
||||
final name = file.name;
|
||||
final length = videoDetailCtr.subtitles.length;
|
||||
if (name.endsWith('.json')) {
|
||||
final file = File(path);
|
||||
final stream = file.openRead().transform(
|
||||
utf8.decoder,
|
||||
);
|
||||
final buffer = StringBuffer();
|
||||
await for (final chunk in stream) {
|
||||
if (!mounted) return;
|
||||
buffer.write(chunk);
|
||||
}
|
||||
if (!mounted) return;
|
||||
String sub = buffer.toString();
|
||||
sub = await compute<List, String>(
|
||||
VideoHttp.processList,
|
||||
jsonDecode(sub)['body'],
|
||||
);
|
||||
if (!mounted) return;
|
||||
videoDetailCtr.vttSubtitles[length] = (
|
||||
isData: true,
|
||||
id: sub,
|
||||
);
|
||||
} else {
|
||||
videoDetailCtr.vttSubtitles[length] = (
|
||||
isData: false,
|
||||
id: path,
|
||||
);
|
||||
}
|
||||
videoDetailCtr.subtitles.add(
|
||||
Subtitle(
|
||||
lan: '',
|
||||
lanDoc: name.split('.').firstOrNull ?? name,
|
||||
),
|
||||
final name = file.name;
|
||||
final length = videoDetailCtr.subtitles.length;
|
||||
if (name.endsWith('.json')) {
|
||||
final file = File(path);
|
||||
final stream = file.openRead().transform(
|
||||
utf8.decoder,
|
||||
);
|
||||
final buffer = StringBuffer();
|
||||
await for (final chunk in stream) {
|
||||
if (!mounted) return;
|
||||
buffer.write(chunk);
|
||||
}
|
||||
if (!mounted) return;
|
||||
String sub = buffer.toString();
|
||||
sub = await compute<List, String>(
|
||||
VideoHttp.processList,
|
||||
jsonDecode(sub)['body'],
|
||||
);
|
||||
if (!mounted) return;
|
||||
videoDetailCtr.vttSubtitles[length] = (
|
||||
isData: true,
|
||||
id: sub,
|
||||
);
|
||||
} else {
|
||||
videoDetailCtr.vttSubtitles[length] = (
|
||||
isData: false,
|
||||
id: path,
|
||||
);
|
||||
await videoDetailCtr.setSubtitle(length + 1);
|
||||
}
|
||||
videoDetailCtr.subtitles.add(
|
||||
Subtitle(
|
||||
lan: '',
|
||||
lanDoc: name.split('.').firstOrNull ?? name,
|
||||
),
|
||||
);
|
||||
await videoDetailCtr.setSubtitle(length + 1);
|
||||
}
|
||||
} catch (e) {
|
||||
SmartDialog.showToast('加载失败: $e');
|
||||
|
||||
Reference in New Issue
Block a user