null pointer exception in song manager?

前端 未结 1 788
独厮守ぢ
独厮守ぢ 2021-01-26 06:22

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 Str         


        
相关标签:
1条回答
  • 2021-01-26 06:25

    Try this :

     String[] STAR = { "*" };
       int totalSongs;
     public void ListAllSongs() 
      {
        Uri allsongsuri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
        String selection = 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 {
                        String songname = cursor
                                .getString(cursor                                        .getColumnIndex(MediaStore.Audio.Media.DISPLAY_NAME));
                        int song_id = cursor.getInt(cursor
                                .getColumnIndex(MediaStore.Audio.Media._ID));
                        String fullpath = cursor.getString(cursor
                                .getColumnIndex(MediaStore.Audio.Media.DATA));
                        fullsongpath.add(fullpath);
                        String albumname = cursor.getString(cursor
                                .getColumnIndex(MediaStore.Audio.Media.ALBUM));
                        int album_id = cursor
                                .getInt(cursor
                                        .getColumnIndex(MediaStore.Audio.Media.ALBUM_ID));
                        String artistname = cursor.getString(cursor
                                .getColumnIndex(MediaStore.Audio.Media.ARTIST));
                        int artist_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.

    0 讨论(0)
提交回复
热议问题