Android Question MusicPlayer problem

Laurie

Member
Licensed User
Longtime User
My music player works perfectly on my old Galaxy but fails on the Galaxy 10.
Lists albums and tracks OK, but selecting a track to play bombs out with instruction MP1.Load(path1, NewFile)

path1 = /storage/emulated/0/Music/Acker Bilk/Stranger on the Shore
Newfile = Hey Jude.mp3

Error is java.lang.NullPointerException: Attempt to invoke virtual method 'void android.media.MediaPlayer.reset()' on a null object reference

Please help,
 

Laurie

Member
Licensed User
Longtime User
Thanks for responding Erel, and as always so quickly, but I don't understand.
I have obtained the Path and filename so why does the mp.load fail? Does ContentChooser provide something other than dir and file name?
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
More recent levels of the Android SDK limit access to external storage. This is probably your problem if you are reusing an old project. It has nothing to do with Music Player. Essentially, you cannot access external storage in current Android versions without getting the User's permission first.

The easiest fix is to use the manifest editor to limit the target sdk level to, say, level 28. I use this with my MusicPlayer app and it works fine on Android 10, although of course it would not be accepted by PlayStore. If you want to produce an app for PlayStore then you will need to learn how to access external storage at current sdk levels, which is where ContentChooser comes in.
 
Upvote 0

Laurie

Member
Licensed User
Longtime User
Thanks Brian, my old (personal) project has sprung back to life. I'll have to try and get my head round ContentChooser for the future though...
 
Upvote 0
Top