To select an audio file using Intent , I am using this function :-
fun selectAudioFromStorage() {
val pictureActionIntent = Intent(Intent.ACTION_GET_CONT
As file paths are not usable in API 29 and above for public files I suggest that you don't try to use them but use a Java FileDescriptor
instead.
As per https://developer.android.com/training/data-storage#scoped-storage
And more specifically https://developer.android.com/training/data-storage/shared/media#open-file-descriptor
A lot of API's allow you to provide a FileDescriptor
instead of a path.
e.g. Use https://developer.android.com/reference/android/media/MediaPlayer.html#setDataSource(java.io.FileDescriptor)
instead of
https://developer.android.com/reference/android/media/MediaPlayer.html#setDataSource(java.lang.String)
To get a fileDescriptor
from a URI do the following (in Java)
ParcelFileDescriptor pfd =
this.getContentResolver().
openFileDescriptor(URI, "r");
FileDescriptor fileDescriptor = pfd.getFileDescriptor();