@@ -73,7 +73,15 @@ class PhotoManagerService {
7373 Future <void > requestPermission () async {
7474 final PermissionState result;
7575 try {
76- result = _permissionState ?? await PhotoManager .requestPermissionExtend ();
76+ result = _permissionState ??
77+ await PhotoManager .requestPermissionExtend (
78+ requestOption: const PermissionRequestOption (
79+ androidPermission: AndroidPermission (
80+ type: RequestType .common,
81+ mediaLocation: false ,
82+ ),
83+ ),
84+ );
7785 } catch (_) {
7886 log ('Failed to request permission!' , name: 'PhotoManagerService' );
7987 throw PermissionException ();
@@ -98,27 +106,31 @@ class PhotoManagerService {
98106 throw PermissionException ();
99107 }
100108
101- final List <AssetEntity >? assets;
102109 try {
103110 final assetPaths = _assetPaths ??
104111 await PhotoManager .getAssetPathList (type: RequestType .audio);
105- final recentAssetPath = assetPaths.isNotEmpty ? assetPaths[0 ] : null ;
106- assets = _assets ??
107- await recentAssetPath? .getAssetListRange (
112+
113+ log ('Found ${assetPaths .length } audio paths' , name: 'PhotoManagerService' );
114+
115+ if (assetPaths.isEmpty) {
116+ // No audio files found on device - return empty list instead of throwing
117+ log ('No audio files found on device' , name: 'PhotoManagerService' );
118+ return [];
119+ }
120+
121+ final recentAssetPath = assetPaths[0 ];
122+ final assets = _assets ??
123+ await recentAssetPath.getAssetListRange (
108124 start: 0 ,
109125 end: 1000 ,
110126 );
111- } catch (_) {
112- log ('Failed to get audio assets!' , name: 'PhotoManagerService' );
127+
128+ log ('Retrieved ${assets .length } audio assets' , name: 'PhotoManagerService' );
129+ return assets;
130+ } catch (e) {
131+ log ('Failed to get audio assets: $e ' , name: 'PhotoManagerService' );
113132 throw GetAudioException ();
114133 }
115-
116- if (assets == null ) {
117- log ('Failed to get audio assets!' , name: 'PhotoManagerService' );
118- throw GetAudioException ();
119- }
120-
121- return assets;
122134 }
123135
124136 /// Gets the video assets.
0 commit comments