Created
January 8, 2016 12:17
-
-
Save vaibhav-jani/735bfb3b955cbdf41f69 to your computer and use it in GitHub Desktop.
MusicStore.Java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public ArrayList<MusicBean> getMusic(){ | |
| ArrayList<MusicBean> alMusic = new ArrayList<>(); | |
| Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; | |
| String[] projection = {MediaStore.Audio.Media._ID, | |
| MediaStore.Audio.Media.ARTIST, MediaStore.Audio.Media.TITLE, | |
| MediaStore.Audio.Media.DATA, MediaStore.Audio.Media.DISPLAY_NAME, | |
| MediaStore.Audio.Media.DURATION, MediaStore.Audio.Media.ALBUM_ID}; | |
| ContentResolver contentResolver = context.getContentResolver(); | |
| String selection = MediaStore.Audio.Media.IS_MUSIC + " != 0"; | |
| Cursor cursor = contentResolver.query(uri,projection, selection, null, null); | |
| if(cursor != null && cursor.moveToFirst()){ | |
| do { | |
| MusicBean musicBean = new MusicBean(); | |
| int _id = cursor.getColumnIndex(MediaStore.Audio.Media._ID); | |
| int name = cursor.getColumnIndex(MediaStore.Audio.Media.DISPLAY_NAME); | |
| int artist = cursor.getColumnIndex(MediaStore.Audio.Media.ARTIST); | |
| int filePath = cursor.getColumnIndex(MediaStore.Audio.Media.DATA); | |
| musicBean.setId(cursor.getString(_id)); | |
| musicBean.setMusicName(cursor.getString(name)); | |
| musicBean.setMusicArtist(cursor.getString(artist)); | |
| musicBean.setFilePath(cursor.getString(filePath)); | |
| alMusic.add(musicBean); | |
| } while (cursor.moveToNext()); | |
| } | |
| return alMusic; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment