on_audio_query
on_audio_query copied to clipboard
feature to delete songs from external storage
below is the code for deleting a song , but this works only for internal storage and does not delete song from external storage .
File file = File(widget.singleTrack!.data);
try {
file.delete();
if (await file.exists()) {
print('Song not deleted');
} else {
widget.allSongs!.remove(widget.singleTrack);
}
} catch (e) {
print('$e');
}
deleting a song from external storage require many permissions from user , it is very complex , adding a function which will handle the permission of asking the user to delete external files (songs) , will be a great . After taking the necessary permission that function should delete the song .
can you add this in future update of the plugin ???
can you add this in future update of the plugin ???
I'll see what i can do, Android has very complex permission system and now, more limited. On the other hand, IOS has a limitation for everything. Probably this feature will be only for Android and Web.
Hi. I'm trying to delete song file also but it is unable to delete and throws an exception of permission denied but permissions are already granted using permission_handler
and required storage permissions are added in AndroidManifest.xml as well. I have also checked file exist before delete which return true. Would you plz help me to solve this.
Error on file.delete() line.
Unhandled Exception: FileSystemException: Deletion failed, path = '/storage/0E15-2E06/Music/Call Sound Effect.mp3' (OS Error: Permission denied, errno = 13)
Code snippet:
if (await Permission.storage.request().isGranted) {
// Either the permission was already granted before or the user just granted it.
// permission was granted
if (song != null) {
String? path = song.data;
File file = File(path);
bool isExist = await file.exists();
if (isExist) {
await file.delete(recursive: true);
}
}
}