1600802039
阿新 • • 發佈:2018-12-11
aud mage isa 音樂 column rst cme href 暫停
實現功能:
1.實現音樂的播放,暫停,上一首,下一首
2.生成播放列表
3.提示音樂信息
4.顯示播放進度條,且進度條可拖拽
實現截圖:
關鍵代碼分析
public ArrayList<MusicMedia> scanAllAudioFiles(){ ArrayList<MusicMedia> mylist = new ArrayList<MusicMedia>(); Cursor cursor = getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null, null, null, MediaStore.Audio.Media.DEFAULT_SORT_ORDER); if(cursor.moveToFirst()){ while (!cursor.isAfterLast()) { int id = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media._ID)); String tilte = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE)); String album= cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM)); int albumId = cursor.getInt(cursor.getColumnIndex(MediaStore.Audio.Media.ALBUM_ID)); String artist = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST)); String url= cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA)); int duration = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DURATION)); Long size = cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.SIZE)); if (size >1024*800){ MusicMedia musicMedia = new MusicMedia(); musicMedia.setId(id); musicMedia.setArtist(artist); musicMedia.setSize(size); musicMedia.setTitle(tilte); musicMedia.setTime(duration); musicMedia.setUrl(url); musicMedia.setAlbum(album); musicMedia.setAlbumId(albumId); mylist.add(musicMedia); } cursor.moveToNext(); } } return mylist; }
此段代碼用於遍歷sd卡的多媒體庫,將所有音樂文件及其各種屬性獲取,並將其顯示在列表中
代碼鏈接:
https://git.dev.tencent.com/gao2039/1600802039.git
apk鏈接:
https://git.dev.tencent.com/gao2039/apk.git
1600802039