2012-07-04 131 views

回答

7

嘗試一下本作API級別10或更高

MediaMetadataRetriever mmr = new MediaMetadataRetriever(); 
mmr.setDataSource(filePath); 

String albumName = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM)); 

等等...

更多help

+0

http://mrbool.com/how-to-extract-meta-data-from-media-file-in-android/28130 –

+1

它的功能就像魔術一樣! – pukingminion

+1

它是否適用於在線mp3音頻文件url? – Gattsu

4
  MediaMetadataRetriever mmr = new MediaMetadataRetriever(); 
     mmr.setDataSource(songsList.get(songIndex).get("songPath")); 
     byte[] artBytes = mmr.getEmbeddedPicture(); 
     if(artBytes!=null) 
      { 
     //  InputStream is = new ByteArrayInputStream(mmr.getEmbeddedPicture()); 
      Bitmap bm = BitmapFactory.decodeByteArray(artBytes, 0, artBytes.length); 
      bSongImage.setImageBitmap(bm); 
     } 
     else 
     { 
      bSongImage.setImageDrawable(getResources().getDrawable(R.drawable.cmp)); 
     } 

否則在音頻文件沒有嵌入圖像

0
MetaDataRetriever m_metaRetriever = new MetaDataRetriever(); 
m_metaRetriever.setDataSource(MainActivity.this,uriSound); 

setDataSource方法的輸入參數也應包含上下文。否則會拋出illigalArgument異常。