|
|
@@ -6,6 +6,20 @@ import 'package:photo_manager/photo_manager.dart';
|
|
|
class AudioPickerUtils {
|
|
|
AudioPickerUtils._();
|
|
|
|
|
|
+ static const List<String> allowFileType = [
|
|
|
+ 'wav',
|
|
|
+ 'mp3',
|
|
|
+ 'm4a',
|
|
|
+ 'flv',
|
|
|
+ 'mp4',
|
|
|
+ 'wma',
|
|
|
+ '3gp',
|
|
|
+ 'amr',
|
|
|
+ 'aac',
|
|
|
+ 'ogg-opus',
|
|
|
+ 'flac'
|
|
|
+ ];
|
|
|
+
|
|
|
//申请权限
|
|
|
static Future<bool> requestPermissionExtend() async {
|
|
|
final PermissionState ps = await PhotoManager.requestPermissionExtend(
|
|
|
@@ -76,21 +90,10 @@ class AudioPickerUtils {
|
|
|
}
|
|
|
|
|
|
//通过平台文件管理器的方式选择单一文件
|
|
|
- static Future<File?> pickSingleFileByPlatform() async {
|
|
|
+ static Future<File?> pickSingleFileByPlatform(
|
|
|
+ {List<String> type = allowFileType}) async {
|
|
|
FilePickerResult? result = await FilePicker.platform
|
|
|
- .pickFiles(type: FileType.custom, allowedExtensions: [
|
|
|
- 'wav',
|
|
|
- 'mp3',
|
|
|
- 'm4a',
|
|
|
- 'flv',
|
|
|
- 'mp4',
|
|
|
- 'wma',
|
|
|
- '3gp',
|
|
|
- 'amr',
|
|
|
- 'aac',
|
|
|
- 'ogg-opus',
|
|
|
- 'flac'
|
|
|
- ]);
|
|
|
+ .pickFiles(type: FileType.custom, allowedExtensions: type);
|
|
|
if (result != null) {
|
|
|
String filePath = result.files.single.path!;
|
|
|
File file = File(filePath);
|