|
|
@@ -122,73 +122,75 @@ class HomePageController extends BaseController {
|
|
|
}
|
|
|
|
|
|
void onPickerAudioFile() async {
|
|
|
- EventHandler.report(EventId.event_100030);
|
|
|
- if (!accountRepository.isLogin.value) {
|
|
|
- Get.toNamed(RoutePath.login);
|
|
|
- ToastUtil.showToast(StringName.errorCodeNoLogin.tr);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- FilePickerResult? result = await FilePicker.platform
|
|
|
- .pickFiles(type: FileType.custom, allowedExtensions: [
|
|
|
- 'wav',
|
|
|
- 'mp3',
|
|
|
- 'm4a',
|
|
|
- 'flv',
|
|
|
- 'mp4',
|
|
|
- 'wma',
|
|
|
- '3gp',
|
|
|
- 'amr',
|
|
|
- 'aac',
|
|
|
- 'ogg-opus',
|
|
|
- 'flac'
|
|
|
- ]);
|
|
|
- if (result != null) {
|
|
|
- LoadingDialog.show(StringName.fileImporting.tr);
|
|
|
- AudioPlayer? player;
|
|
|
- try {
|
|
|
- String filePath = result.files.single.path!;
|
|
|
- File file = File(filePath);
|
|
|
- //文件不能超过500M
|
|
|
- if (file.lengthSync() > 500 * 1024 * 1024) {
|
|
|
- ToastUtil.showToast(StringName.fileChoiceSizeLimit.tr);
|
|
|
- return;
|
|
|
- }
|
|
|
- player = AudioPlayer();
|
|
|
- player.setAudioSource(AudioSource.uri(file.uri));
|
|
|
- Duration? duration = await player.durationStream
|
|
|
- .firstWhere((duration) => duration != null);
|
|
|
- if (duration == null) {
|
|
|
- ToastUtil.showToast(StringName.fileAudioDurationCannotObtained.tr);
|
|
|
- return;
|
|
|
- }
|
|
|
- //录音时长不能超过5小时
|
|
|
- if (duration.inHours > 5) {
|
|
|
- ToastUtil.showToast(StringName.fileAudioDurationLimit.tr);
|
|
|
- return;
|
|
|
- }
|
|
|
- late TalkBean bean;
|
|
|
- try {
|
|
|
- bean = await talkRepository.talkCreate(
|
|
|
- const Uuid().v4(), duration.inSeconds,
|
|
|
- localAudioUrl: filePath, uploadType: 1);
|
|
|
- } catch (e) {
|
|
|
- ErrorHandler.toastError(e);
|
|
|
- return;
|
|
|
- }
|
|
|
- String childDirName = bean.id;
|
|
|
- Directory dir = await _getChoiceUploadDir(childDirName);
|
|
|
-
|
|
|
- await moveFileToDirectory(file, dir);
|
|
|
-
|
|
|
- TalkPage.start(bean);
|
|
|
- } catch (e) {
|
|
|
- ErrorHandler.toastError(e, message: StringName.fileImportFail.tr);
|
|
|
- } finally {
|
|
|
- player?.dispose();
|
|
|
- LoadingDialog.hide();
|
|
|
- }
|
|
|
- }
|
|
|
+ Get.toNamed(RoutePath.audioPicker);
|
|
|
+
|
|
|
+ // EventHandler.report(EventId.event_100030);
|
|
|
+ // if (!accountRepository.isLogin.value) {
|
|
|
+ // Get.toNamed(RoutePath.login);
|
|
|
+ // ToastUtil.showToast(StringName.errorCodeNoLogin.tr);
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // FilePickerResult? result = await FilePicker.platform
|
|
|
+ // .pickFiles(type: FileType.custom, allowedExtensions: [
|
|
|
+ // 'wav',
|
|
|
+ // 'mp3',
|
|
|
+ // 'm4a',
|
|
|
+ // 'flv',
|
|
|
+ // 'mp4',
|
|
|
+ // 'wma',
|
|
|
+ // '3gp',
|
|
|
+ // 'amr',
|
|
|
+ // 'aac',
|
|
|
+ // 'ogg-opus',
|
|
|
+ // 'flac'
|
|
|
+ // ]);
|
|
|
+ // if (result != null) {
|
|
|
+ // LoadingDialog.show(StringName.fileImporting.tr);
|
|
|
+ // AudioPlayer? player;
|
|
|
+ // try {
|
|
|
+ // String filePath = result.files.single.path!;
|
|
|
+ // File file = File(filePath);
|
|
|
+ // //文件不能超过500M
|
|
|
+ // if (file.lengthSync() > 500 * 1024 * 1024) {
|
|
|
+ // ToastUtil.showToast(StringName.fileChoiceSizeLimit.tr);
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+ // player = AudioPlayer();
|
|
|
+ // player.setAudioSource(AudioSource.uri(file.uri));
|
|
|
+ // Duration? duration = await player.durationStream
|
|
|
+ // .firstWhere((duration) => duration != null);
|
|
|
+ // if (duration == null) {
|
|
|
+ // ToastUtil.showToast(StringName.fileAudioDurationCannotObtained.tr);
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+ // //录音时长不能超过5小时
|
|
|
+ // if (duration.inHours > 5) {
|
|
|
+ // ToastUtil.showToast(StringName.fileAudioDurationLimit.tr);
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+ // late TalkBean bean;
|
|
|
+ // try {
|
|
|
+ // bean = await talkRepository.talkCreate(
|
|
|
+ // const Uuid().v4(), duration.inSeconds,
|
|
|
+ // localAudioUrl: filePath, uploadType: 1);
|
|
|
+ // } catch (e) {
|
|
|
+ // ErrorHandler.toastError(e);
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+ // String childDirName = bean.id;
|
|
|
+ // Directory dir = await _getChoiceUploadDir(childDirName);
|
|
|
+ //
|
|
|
+ // await moveFileToDirectory(file, dir);
|
|
|
+ //
|
|
|
+ // TalkPage.start(bean);
|
|
|
+ // } catch (e) {
|
|
|
+ // ErrorHandler.toastError(e, message: StringName.fileImportFail.tr);
|
|
|
+ // } finally {
|
|
|
+ // player?.dispose();
|
|
|
+ // LoadingDialog.hide();
|
|
|
+ // }
|
|
|
+ // }
|
|
|
}
|
|
|
|
|
|
Future<void> moveFileToDirectory(File file, Directory dir) async {
|