Whenever I run code it works fine for a song which has no space in it's name
Check this line of code : metaRetriver.setDataSource("/storage/emulated/0/song.mp3");
Here their is a MP3 file with no space (song.mp3)
But whenever I change the song which has spaces in its name, it throws IllegalArgumentException
on this line metaRetriver.setDataSource("/storage/emulated/0/Bom Diggy Diggy.mp3");
Ofcource I can't rename every single file for removing spaces in them.
Here is my code,
public class MainActivity extends AppCompatActivity {
MediaMetadataRetriever metaRetriver;
byte[] art;
ImageView album_art;
Bitmap songImage;
String thePath;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getInit();
metaRetriver = new MediaMetadataRetriever();
metaRetriver.setDataSource("/storage/emulated/0/"+ URLEncoder.encode("Bom Diggy Diggy.mp3"));
art = metaRetriver.getEmbeddedPicture();
if (art != null) {
songImage = BitmapFactory
.decodeByteArray(art, 0, art.length);
album_art.setImageBitmap(songImage);
} else {
String error = "art is null";
Log.i("lolol", error);
}
}
public void getInit () {
album_art = (ImageView) findViewById(R.id.album_art);
}
}`
Can anyone help me in solving this problem