|
|
@ -12,6 +12,7 @@ import 'package:path_provider/path_provider.dart'; |
|
|
import 'package:permission_handler/permission_handler.dart'; |
|
|
import 'package:permission_handler/permission_handler.dart'; |
|
|
|
|
|
|
|
|
import '../../../core/utils/logger.dart'; |
|
|
import '../../../core/utils/logger.dart'; |
|
|
|
|
|
import '../../../core/utils/synchrodata.dart'; |
|
|
import '../../../core/utils/upload_oss.dart'; |
|
|
import '../../../core/utils/upload_oss.dart'; |
|
|
import '../../../data/services/db/sqflite_api.dart'; |
|
|
import '../../../data/services/db/sqflite_api.dart'; |
|
|
import '../../../core/utils/permission_util.dart'; |
|
|
import '../../../core/utils/permission_util.dart'; |
|
|
@ -32,9 +33,6 @@ class MeetingController extends GetxController { |
|
|
List<String> selected = []; |
|
|
List<String> selected = []; |
|
|
|
|
|
|
|
|
final appDocDir = getApplicationDocumentsDirectory(); |
|
|
final appDocDir = getApplicationDocumentsDirectory(); |
|
|
//final appopus = getExternalStorageDirectories(); |
|
|
|
|
|
// final directory = Directory( |
|
|
|
|
|
// '/storage/emulated/0/Android/data/com.yunqiinnovation.deepsound/files'); |
|
|
|
|
|
List<FileSystemEntity> files = []; |
|
|
List<FileSystemEntity> files = []; |
|
|
TextEditingController titleController = TextEditingController(); // 录音标题 |
|
|
TextEditingController titleController = TextEditingController(); // 录音标题 |
|
|
|
|
|
|
|
|
@ -55,7 +53,6 @@ class MeetingController extends GetxController { |
|
|
super.onInit(); |
|
|
super.onInit(); |
|
|
listController.addListener(_onScroll); |
|
|
listController.addListener(_onScroll); |
|
|
_requestStoragePermission(); |
|
|
_requestStoragePermission(); |
|
|
//Permission.storage.request(); |
|
|
|
|
|
_headers = { |
|
|
_headers = { |
|
|
'Authorization': 'Bearer; $_token', |
|
|
'Authorization': 'Bearer; $_token', |
|
|
'Content-Type': 'application/json', |
|
|
'Content-Type': 'application/json', |
|
|
@ -64,7 +61,7 @@ class MeetingController extends GetxController { |
|
|
addMeetingAudio(); |
|
|
addMeetingAudio(); |
|
|
final Map<String, dynamic> args = Get.arguments ?? {}; |
|
|
final Map<String, dynamic> args = Get.arguments ?? {}; |
|
|
// 检查参数是否存在且包含有效路径 |
|
|
// 检查参数是否存在且包含有效路径 |
|
|
if (args != null && |
|
|
if (args.isNotEmpty && |
|
|
args.containsKey('filePath') && |
|
|
args.containsKey('filePath') && |
|
|
args['filePath'] is String && |
|
|
args['filePath'] is String && |
|
|
args['filePath'].isNotEmpty) { |
|
|
args['filePath'].isNotEmpty) { |
|
|
@ -82,6 +79,10 @@ class MeetingController extends GetxController { |
|
|
super.onClose(); |
|
|
super.onClose(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void onPopInvokedWithResult(didPop, result) { |
|
|
|
|
|
Synchrodata.startSynchro(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
void _onScroll() { |
|
|
void _onScroll() { |
|
|
if (isGetMore && |
|
|
if (isGetMore && |
|
|
!isLoading && |
|
|
!isLoading && |
|
|
@ -109,11 +110,8 @@ class MeetingController extends GetxController { |
|
|
|
|
|
|
|
|
// 请求存储权限 |
|
|
// 请求存储权限 |
|
|
void _requestStoragePermission() async { |
|
|
void _requestStoragePermission() async { |
|
|
// final BuildContext context = Get.overlayContext!; |
|
|
|
|
|
|
|
|
|
|
|
PermissionUtil.instance |
|
|
PermissionUtil.instance |
|
|
.requestPermission( |
|
|
.requestPermission( |
|
|
// context: context, |
|
|
|
|
|
permissionType: Permission.storage, |
|
|
permissionType: Permission.storage, |
|
|
permissionName: "存储", |
|
|
permissionName: "存储", |
|
|
explanationText: "我们需要访问存储权限,以便您可以选择并上传音频文件。", |
|
|
explanationText: "我们需要访问存储权限,以便您可以选择并上传音频文件。", |
|
|
@ -124,18 +122,14 @@ class MeetingController extends GetxController { |
|
|
Logger.d("Permission", "用户授予了存储权限"); |
|
|
Logger.d("Permission", "用户授予了存储权限"); |
|
|
} else { |
|
|
} else { |
|
|
Logger.d("Permission", "用户未授予存储权限"); |
|
|
Logger.d("Permission", "用户未授予存储权限"); |
|
|
// 可以提示用户无法进行文件操作 |
|
|
|
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void loadTranslatopus() async { |
|
|
void loadTranslatopus() async { |
|
|
// final appDir = await appopus; // 先 await 获取目录 |
|
|
|
|
|
final dir = |
|
|
final dir = |
|
|
Directory("/data/user/0/com.yunqiinnovation.deepsound/files/OpusAudio"); |
|
|
Directory("/data/user/0/com.yunqiinnovation.deepsound/files/OpusAudio"); |
|
|
|
|
|
|
|
|
print("appDocDir=${dir?.path}"); |
|
|
|
|
|
|
|
|
|
|
|
files = dir |
|
|
files = dir |
|
|
.listSync() |
|
|
.listSync() |
|
|
.where((f) => f is File && (f.path.endsWith('.opus'))) |
|
|
.where((f) => f is File && (f.path.endsWith('.opus'))) |
|
|
@ -147,15 +141,12 @@ class MeetingController extends GetxController { |
|
|
final appDir = await appDocDir; // 先 await 获取目录 |
|
|
final appDir = await appDocDir; // 先 await 获取目录 |
|
|
final dir = Directory("${appDir.path}/TranslatAudio"); |
|
|
final dir = Directory("${appDir.path}/TranslatAudio"); |
|
|
|
|
|
|
|
|
print("appDocDir=${dir?.path}"); |
|
|
|
|
|
// Create directory if it doesn't exist |
|
|
|
|
|
if (!await dir.exists()) { |
|
|
if (!await dir.exists()) { |
|
|
await dir.create(recursive: true); // Create directory tree if needed |
|
|
await dir.create(recursive: true); |
|
|
files = []; // No files exist in new directory |
|
|
files = []; |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Directory exis |
|
|
|
|
|
files = dir |
|
|
files = dir |
|
|
.listSync() |
|
|
.listSync() |
|
|
.where((f) => |
|
|
.where((f) => |
|
|
@ -168,20 +159,12 @@ class MeetingController extends GetxController { |
|
|
f.path.endsWith('.mov'))) |
|
|
f.path.endsWith('.mov'))) |
|
|
.toList(); |
|
|
.toList(); |
|
|
} catch (e) { |
|
|
} catch (e) { |
|
|
print("Error loading files: $e"); |
|
|
files = []; |
|
|
files = []; // Return empty list on error |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
// 导入音频文件 |
|
|
|
|
|
|
|
|
|
|
|
Future<void> shareAllTranslatAudio() async { |
|
|
Future<void> shareAllTranslatAudio() async { |
|
|
final filePath = selected[0]; |
|
|
final filePath = selected[0]; |
|
|
// for (final filePath in selected) { |
|
|
|
|
|
// if (filePath.isEmpty) { |
|
|
|
|
|
// EasyLoading.showToast('没有可分享的音频文件'); |
|
|
|
|
|
// return; |
|
|
|
|
|
// } |
|
|
|
|
|
// } |
|
|
|
|
|
try { |
|
|
try { |
|
|
await Share.shareXFiles( |
|
|
await Share.shareXFiles( |
|
|
[XFile(filePath)], |
|
|
[XFile(filePath)], |
|
|
@ -216,7 +199,7 @@ class MeetingController extends GetxController { |
|
|
final files = |
|
|
final files = |
|
|
await sourceDir.list().where((entity) => entity is File).toList(); |
|
|
await sourceDir.list().where((entity) => entity is File).toList(); |
|
|
|
|
|
|
|
|
int addQuantity = 0; |
|
|
int addUp = 0; |
|
|
for (final fileEntity in files) { |
|
|
for (final fileEntity in files) { |
|
|
try { |
|
|
try { |
|
|
final file = File(fileEntity.path); |
|
|
final file = File(fileEntity.path); |
|
|
@ -225,8 +208,6 @@ class MeetingController extends GetxController { |
|
|
// 设置音频源获取时长 |
|
|
// 设置音频源获取时长 |
|
|
|
|
|
|
|
|
await _audioPlayer.setAudioSource(AudioSource.file(filePath)); |
|
|
await _audioPlayer.setAudioSource(AudioSource.file(filePath)); |
|
|
print( |
|
|
|
|
|
"_audioPlayer$_audioPlayer,filePath=$filePath,_audioPlayer.duration?.inSeconds${_audioPlayer.duration?.inSeconds}"); |
|
|
|
|
|
int seconds = _audioPlayer.duration?.inSeconds ?? 0; |
|
|
int seconds = _audioPlayer.duration?.inSeconds ?? 0; |
|
|
|
|
|
|
|
|
// 获取文件修改时间 |
|
|
// 获取文件修改时间 |
|
|
@ -251,7 +232,6 @@ class MeetingController extends GetxController { |
|
|
'tasktype': 0, |
|
|
'tasktype': 0, |
|
|
'creationtime': creationTime, |
|
|
'creationtime': creationTime, |
|
|
}; |
|
|
}; |
|
|
print("导入数据: $data"); |
|
|
|
|
|
|
|
|
|
|
|
// 插入数据库 |
|
|
// 插入数据库 |
|
|
final meetingId = await SqfliteApi.insertMeeting(data); |
|
|
final meetingId = await SqfliteApi.insertMeeting(data); |
|
|
@ -268,12 +248,13 @@ class MeetingController extends GetxController { |
|
|
await file.delete(); |
|
|
await file.delete(); |
|
|
|
|
|
|
|
|
addQuantity++; |
|
|
addQuantity++; |
|
|
|
|
|
addUp++; |
|
|
} |
|
|
} |
|
|
} catch (e) { |
|
|
} catch (e) { |
|
|
print("文件处理失败: ${fileEntity.path}, 错误: $e"); |
|
|
print("文件处理失败: ${fileEntity.path}, 错误: $e"); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
if (addQuantity > 0) EasyLoading.showSuccess('成功导入本地 $addQuantity 条录音'); |
|
|
if (addUp > 0) EasyLoading.showSuccess('成功导入本地 $addUp 条录音'); |
|
|
} catch (e) { |
|
|
} catch (e) { |
|
|
EasyLoading.showError('导入失败: $e'); |
|
|
EasyLoading.showError('导入失败: $e'); |
|
|
} finally { |
|
|
} finally { |
|
|
@ -292,7 +273,6 @@ class MeetingController extends GetxController { |
|
|
filepath: filePath, rootDir: 'TranslatAudio'); |
|
|
filepath: filePath, rootDir: 'TranslatAudio'); |
|
|
int seconds = _audioPlayer.duration?.inSeconds ?? 0; |
|
|
int seconds = _audioPlayer.duration?.inSeconds ?? 0; |
|
|
final fileName = filePath.split('/').last; |
|
|
final fileName = filePath.split('/').last; |
|
|
// int creationTime = DateTime.now().millisecondsSinceEpoch; |
|
|
|
|
|
Map<String, Object?> data = { |
|
|
Map<String, Object?> data = { |
|
|
'title': fileName, |
|
|
'title': fileName, |
|
|
'type': 'TRANSLAT', |
|
|
'type': 'TRANSLAT', |
|
|
@ -302,7 +282,6 @@ class MeetingController extends GetxController { |
|
|
'tasktype': 0, |
|
|
'tasktype': 0, |
|
|
'creationtime': creationTime, |
|
|
'creationtime': creationTime, |
|
|
}; |
|
|
}; |
|
|
print("data=$data"); |
|
|
|
|
|
final meetingId = await SqfliteApi.insertMeeting(data); |
|
|
final meetingId = await SqfliteApi.insertMeeting(data); |
|
|
if (meetingId != null) { |
|
|
if (meetingId != null) { |
|
|
dataList.insert(0, { |
|
|
dataList.insert(0, { |
|
|
@ -314,7 +293,6 @@ class MeetingController extends GetxController { |
|
|
} |
|
|
} |
|
|
} catch (e) { |
|
|
} catch (e) { |
|
|
Logger.error('导入文件失败: $filePath, error: $e'); |
|
|
Logger.error('导入文件失败: $filePath, error: $e'); |
|
|
// 可选:继续导入下一个文件 |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
EasyLoading.dismiss(); |
|
|
EasyLoading.dismiss(); |
|
|
|