我的媒体播放器播放列表在下面的android studio的列表视图中仅复制了一首歌曲是我的播放列表代码

时间:2018-08-07 02:06:19

标签: java android listview

我的媒体播放器播放列表在下面的android studio列表视图中仅复制一首歌曲是我的播放列表代码

    //init vars

    ListView songview = (ListView) findViewById(R.id.song_list);

    songList = new ArrayList<Song>();
    getSongList();

    Collections.sort(songList, new Comparator<Song>(){
        public int compare(Song a, Song b ){
            return a.getTitle().compareTo(b.getTitle());
        }
    });
    SongAdapter songAdt = new SongAdapter(this, songList);
    songview.setAdapter(songAdt);
}

public void getSongList() {
    //retrieve Song info
    ContentResolver musicResolver = getContentResolver();
    Uri musicUri = android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
    Cursor musicCursor = musicResolver.query(musicUri, null, null, null, null);

    if(musicCursor !=null && musicCursor.moveToFirst()){
        //get columns
        int titleColumn = musicCursor.getColumnIndex
                (android.provider.MediaStore.Audio.Media.TITLE);
        int idColumn = musicCursor.getColumnIndex
                (android.provider.MediaStore.Audio.Media._ID);
        int artistColumn = musicCursor.getColumnIndex
                (android.provider.MediaStore.Audio.Media.ARTIST);

        //add songs to list
        do {
            long thisId = musicCursor.getLong(idColumn);
            String thisTitle = musicCursor.getString(titleColumn);
            String thisArtist = musicCursor.getString(artistColumn);
            songList.add(new Song(thisId, thisTitle, thisArtist));
        }
        while (musicCursor.moveToNext());
    }
}

这是我的播放列表Java类, SD卡中有五首歌曲,并且使用模拟器运行我的应用程序,但我的播放列表仅检测到一首歌曲,并在{{ 1}}。谁能帮我。

0 个答案:

没有答案