0

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

yosaga
  • 15
  • 8
  • Have you tried escaping the spaces like that :`metaRetriver.setDataSource("/storage/emulated/0/Bom\\ Diggy\\ Diggy.mp3");` ? – StephaneM May 22 '18 at 12:56

1 Answers1

0

You can use Glide library to get album art from audio file. By creating AudioModule.

Jitendra Singh
  • 200
  • 4
  • 17