Reputation: 71
I am using a URI that i pass to a MediaPlayer on android like this:
mediaPlayer.setDataSource(context, Uri.parse(<uri>));
When I get it using Intent.createChooser, it plays once then trying to make it play it again result in java.io.IOException: setDataSource failed.: status=0x80000000.
When i pass the URI as a string directly, it results in java.io.IOException: setDataSource failed.: status=0x80000000, despite the URI outputed by the selector being always the same.
The uri look like this: "content://com.android.providers.media.documents/document/audio%3A21739".
Can someone please enlighten on why does this happen?
Upvotes: 3
Views: 213
Reputation: 71
Turns out android required some weird permissions shenanigans, the solutions was using a different opening coupled with using some sort of permission requirement that somehow output the same uri, but with a persistent access:
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.setType("*/*");
intent.addCategory(Intent.CATEGORY_OPENABLE);
startActivityForResult(Intent.createChooser(intent, "Select file to add"), ADD_2);
In onActivityResult:
if (resultCode == RESULT_OK) {
Uri uri = data.getData();
final int takeFlags = data.getFlags() & Intent.FLAG_GRANT_READ_URI_PERMISSION;
getContentResolver().takePersistableUriPermission(uri, takeFlags);
Log.d(TAG, "Added track uri: " + uri);
playlist.add(uri.toString());
adapter.notifyDataSetChanged();
}
Upvotes: 2