Skip to content Skip to sidebar Skip to footer

Null Pointer Exception In Song Manager?

I am trying this code for geting a playlist. final String MEDIA_PATH=new String(MediaStore.Audio.Media.IS_MUSIC+'!=0'); //final String MEDIA_PATH=new String(MediaStore.Video.

Solution 1:

Try this :

 String[] STAR = { "*" };
   int totalSongs;
 publicvoidListAllSongs() 
  {
    Uriallsongsuri= MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
    Stringselection= MediaStore.Audio.Media.IS_MUSIC + " != 0";
    if (MusicUtils.isSdPresent()) {
        cursor = managedQuery(allsongsuri, STAR, selection, null, null);
        totalSongs = cursor.getCount();
        if (cursor != null) {
            if (cursor.moveToFirst()) {
                do {
                    Stringsongname= cursor
                            .getString(cursor                                        .getColumnIndex(MediaStore.Audio.Media.DISPLAY_NAME));
                    intsong_id= cursor.getInt(cursor
                            .getColumnIndex(MediaStore.Audio.Media._ID));
                    Stringfullpath= cursor.getString(cursor
                            .getColumnIndex(MediaStore.Audio.Media.DATA));
                    fullsongpath.add(fullpath);
                    Stringalbumname= cursor.getString(cursor
                            .getColumnIndex(MediaStore.Audio.Media.ALBUM));
                    intalbum_id= cursor
                            .getInt(cursor
                                    .getColumnIndex(MediaStore.Audio.Media.ALBUM_ID));
                    Stringartistname= cursor.getString(cursor
                            .getColumnIndex(MediaStore.Audio.Media.ARTIST));
                    intartist_id= cursor
                            .getInt(cursor
                                    .getColumnIndex(MediaStore.Audio.Media.ARTIST_ID));
                                            } while (cursor.moveToNext());
            }
            cursor.close();
        }
    }
 }

EDITED:

You check out the below links to show all video file stored in your sd card in a listview.

1) Link 1 2) Link 2 3) Link 3

I hope it will help you .

Thanks.

Post a Comment for "Null Pointer Exception In Song Manager?"