Android - 通過系統資料庫擷取SD卡音樂媒體資訊

來源:互聯網
上載者:User

標籤:android   style   blog   color   使用   檔案   資料   io   

當寫一些東西(比如音樂播放器)的時候,就需要SD卡的mp3列表了~開始我是使用列檔案來著,但是再擷取檔案的資訊(歌手,專輯,圖片,時間長度等。。)很麻煩,所以直接用這個函數了~

 1     private void getMusicPaths(){ 2         // 3         // 擷取音樂列表 4         // 5         Cursor cursor = getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null, null, null, MediaStore.Audio.Media.DEFAULT_SORT_ORDER); 6         if(cursor.moveToFirst()){ 7             while (!cursor.isAfterLast()) {  8                 //歌曲編號 9                 //int id = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media._ID));  10                 //歌曲標題11                 String tilte = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE));  12                 //歌曲的專輯名:MediaStore.Audio.Media.ALBUM13                 //String album = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM));  14                 //歌曲的歌手名: MediaStore.Audio.Media.ARTIST15                 String artist = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST));  16                 //歌曲檔案的路徑 :MediaStore.Audio.Media.DATA17                 String url = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA));   18                 //歌曲的總播放時間長度 :MediaStore.Audio.Media.DURATION19                 //int duration = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DURATION));    20                 //歌曲檔案的大小 :MediaStore.Audio.Media.SIZE21                 //Long size = cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.SIZE));22                 cursor.moveToNext(); 23             } 24         }25     }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.