Play playlist with MediaPlayer

Posted by Kaloer on Stack Overflow See other posts from Stack Overflow or by Kaloer
Published on 2010-01-08T20:23:31Z Indexed on 2010/03/28 8:43 UTC
Read the original article Hit count: 222

Filed under:

Hi, I'm trying to play a playlist I get using the MediaStore provider. However, when I try playing a playlist nothing happens. Can a MediaPlayer play a playlist (m3u file) and do I need to set the first track to play ?

This is my test code in the onCreate() method:

        Uri uri = MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI;
    if(uri == null) {
        Log.e("Uri = null");
    }
    String[] projection = new String[] { MediaStore.Audio.Playlists._ID, MediaStore.Audio.Playlists.NAME, MediaStore.Audio.Playlists.DATA };
    Cursor c = managedQuery(uri, projection, null, null, null);
    if(c == null) {
        Toast.makeText(getApplicationContext(), R.string.alarm_tone_picker_error, Toast.LENGTH_LONG).show();
        return;
    }
    if(!c.moveToFirst()) {
        c.close();
        Toast.makeText(getApplicationContext(), R.string.alarm_tone_picker_no_music, Toast.LENGTH_LONG).show();
        return;
    }
    c.moveToFirst();
    try {
        MediaPlayer player = new MediaPlayer();
        player.setDataSource(c.getString(2));
        player.start();
    } catch(Exception e) {
        e.printStackTrace();
    }

I have turned on every volume stream.

Thanks you,

Kaloer

© Stack Overflow or respective owner

Related posts about android