Reputation: 340
The problem is that when we use a uri
to get the instance of Mediaplayer
class using Mediaplayer.create(Context, uri)
it throws exception
as of below :
java.lang.IllegalArgumentException
The above exception occurs when we have path of music files is in Url Encoded form (i.e,path : storage/sdcard/song%20music%20file.mp3
) the path is of phone storage
and not the url
of song on internet.
Uri uri = Uri.parse(path);
//the below line creates the problem.
mediaplayer = Mediaplayer.create(context, uri);
while in other cases of path of the files it works like charm why this problem occurs and if there is any way of resolving this problem how can we do this ? Any suggestion,help will be appreciated.
Upvotes: 1
Views: 109
Reputation: 86
You can use code like below to solve the issue :
Uri myUri = Uri.parse(Uri.encode(path));
//then use myUri like
mediaplayer = Mediaplayer.create(context, myUri);
Upvotes: 1