Android Question Exoplayer unexpected loader exception

PaulMeuris

Active Member
Licensed User
I am using Exoplayer in a new project to play audio and video files.
In the detail page I have put a button to play the file. The content string comes from a database field that was filled earlier using the content chooser.
When i press the play button i catch the Permission Denial error in the Exoplayer error event.
On the same detail page i have placed another button to start the content chooser. I press that button.
In the content chooser i tap on the same file.
Back in the detail page i check the filename again and it is the same string. Only now the exoplayer is ready to play.
I press the play button again and the exoplayer plays the file.
What does the content chooser do more that i don't do in the first instance?
Or in other words: how can i obtain access to the file?

Log details:
*** detail: B4XPage_Created [mainpage]
*** mainpage: B4XPage_Disappear [mainpage]
*** detail: B4XPage_Appear [mainpage]
content://com.android.providers.media.documents/document/audio%3A1624
Error: com.google.android.exoplayer2.upstream.Loader$UnexpectedLoaderException: Unexpected SecurityException: Permission Denial: opening provider com.android.providers.media.MediaDocumentsProvider from ProcessRecord{7abac20 27629:b4a.mymedia/u0a251} (pid=27629, uid=10251) requires that you obtain access using ACTION_OPEN_DOCUMENT or related APIs
** Activity (main) Pause event (activity is not paused). **
*** detail: B4XPage_Disappear [mainpage, detail]
sending message to waiting queue (OnActivityResult)
running waiting messages (1)
ContentDir
content://com.android.providers.media.documents/document/audio%3A1624
** Activity (main) Resume **
*** detail: B4XPage_Appear [mainpage, detail]
content://com.android.providers.media.documents/document/audio%3A1624
Ready

I use this exoplayer library (the zip file contains version 1.42)

I searched the community forums and found this thread. No replies on it.

Any suggestions?
 

PaulMeuris

Active Member
Licensed User
The URI is a key for an external app which acts as the "document provider". You cannot assume that it will work forever. You need to get a new key each time.
Thank you Erel for the feedback.
Here are some texts i found on developer.android.com:
To preserve access to files across device restarts and create a better user experience, your app can "take" the persistable URI permission grant that the system offers.
Caution: Even after calling takePersistableUriPermission(), your app doesn't retain access to the URI if the associated document is moved or deleted. In those cases, you need to ask permission again to regain access to the URI.
In my app when the content chooser is used for a certain file then that URI remains available during the run of the app.
The content URI that was stored in the database can be reused so it seems to play the file again as long as the app is running.
 
Upvote 0
Top