Browse Source

添加校验是否音频文件

newdev_shunjiawei
tanlongsheng 1 year ago
parent
commit
bafa3cacff
  1. 19
      lib/modules/meeting/controllers/meeting_home_controller.dart

19
lib/modules/meeting/controllers/meeting_home_controller.dart

@ -308,6 +308,19 @@ class MeetingHomeController extends GetxController {
); );
if (result != null) { if (result != null) {
PlatformFile file = result.files.first; PlatformFile file = result.files.first;
if (!_isAudioFile(file.name)) {
Get.snackbar(
'error'.tr, // 错误
'请选择音频文件',
snackPosition: SnackPosition.TOP,
backgroundColor: Colors.red.withOpacity(0.1),
colorText: Colors.red,
);
EasyLoading.dismiss();
return;
}
filePath = await _saveFile(file); filePath = await _saveFile(file);
fileName = file.name; fileName = file.name;
} else { } else {
@ -424,4 +437,10 @@ class MeetingHomeController extends GetxController {
await file.delete(); await file.delete();
} }
} }
bool _isAudioFile(String fileName) {
const List audioExtensions = ['.mp3', '.wav', '.m4a', '.aac'];
final extension = path.extension(fileName).toLowerCase();
return audioExtensions.contains(extension);
}
} }

Loading…
Cancel
Save