I've got a working solution for this problem, it involves 1 JNI call to get a ParcelFileDescriptor
in order to then get the appropriate FD that can be used on OpenSLES natively.
Just need to keep in mind to save the ParcelFileDescriptor
for closing the FD at the end and not getting garbage collected.
Note: The API Level required is 12 to get the FD
Note2: If you wnt you can detachFd()
and then you must close the FD on native code and do not need to keep the reference.
static public ParcelFileDescriptor getFileDescriptor(Context context) {
Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
ContentResolver contentResolver = context.getContentResolver();
ParcelFileDescriptor openFileDescriptor;
try {
openFileDescriptor = contentResolver.openFileDescriptor(uri, "r");
} catch (FileNotFoundException e) {
return null;
}
return openFileDescriptor;
}