Play a sound from Shared folder
/Music
on Android 11+ (but some also applies to Android < 11)
I copied an audio file (sound.ogg) from the assets into the Shared
folder /Music
and wanted to play it from there with the Player
component. (It doesn’t matter here how I copied it from the assets.)
Player.Source
→ /storage/emulated/0/Music/sound.ogg
(absolute path).
Player.Start
Problems / bugs (with APK):
-
The sound is not played
-
Obviously
READ
permission is required here (incorrectly) and must therefore be declared in the Manifest (which is not the case).
(This should be only required if the file was not created by the app itself.) -
After I added this permission to the Manifest (using my extension
DeclareReadWrite
) the permission is not requested automatically. -
After I did this manually, the sound is again not played (“unable to load …”)
-
Only after changing the absolute path to a full path (
Player.Source
) it finally works.
Some bugs / problems too much for most (at least for a “normal” user), I think!
Hence my suggestion/recommendation to the Kodular team (same applies for MIT):
The easiest and best way to deal with all these permission bugs/problems (not just this problem here with the
Player
component) is the following (IMHO):
-
Declare
READ
andWRITE
always (WRITE
up to Android 10). -
Remove all automatic requesting of storage permissions from all components.
-
Let the user decide where, when, which storage permission should/must be requested manually on which Android version.
Usually as follows: (For more details see → here )
If API < 30, requestREAD
and / orWRITE
, else requestREAD
(only if the file is a media file and is not created by the app itself).
Google has overcomplicated the new Android filesystem (totally unnecessarily) so that NOBODY can avoid looking into it deeply before anyone builds apps since
targetSdkVersion=30
.
Sorry if not everyone can follow me because this is really advanced stuff.