标签:拖拽 .data fir 播放 isa 分享图片 get class nal
实现功能:
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
标签:拖拽 .data fir 播放 isa 分享图片 get class nal
原文地址:https://www.cnblogs.com/gao98/p/10104321.html