2011-04-28 262 views
0

我已錄製3gp格式的音頻,並將其保存在SD卡中..這是我的代碼,它運行sucessfull ..我需要添加圖像到該音頻文件,以便添加的圖像將是專輯封面&當我嘗試播放從SD卡位置的android..like這個默認媒體播放器所記錄的聲音..在Android中錄製音頻

enter image description here

圖片中顯示的圖像是專輯封面,我有把它給我錄製的音頻文件

/** 
* Starts a new recording. 
*/ 
public void start() throws IOException { 
String state = android.os.Environment.getExternalStorageState(); 
if (!state.equals(android.os.Environment.MEDIA_MOUNTED)) { 
    throw new IOException("SD Card is not mounted. It is " + state 
     + "."); 
} 

// make sure the directory we plan to store the recording in exists 
File directory = new File(path).getParentFile(); 
if (!directory.exists() && !directory.mkdirs()) { 
    throw new IOException("Path to file could not be created."); 
} 

recorder.setAudioSource(MediaRecorder.AudioSource.MIC); 
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); 
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); 
System.out.println("audio_file_path : = " + path); 
recorder.setOutputFile(path); 
recorder.prepare(); 

recorder.start(); // Recording is now started 




} 

回答

1

如果您只需要該文件在Android Media Player中展示藝術品,請考慮使用Google Content Provider添加專輯封面。在創建3GP文件後,使用MediaScannerConnection API對其進行掃描。將其添加到數據庫後,您可以在您的活動或服務中使用ContentResolver進行訪問。 MediaScannerConnection將爲您提供新創建的文件的URI。您可以嘗試將您想要的新作品放置在SD卡上的某個位置。然後,致電:getContentResolver().udpate(uri, newArtContentValue, null, null)newArtContentValueContentValue對象的一個​​實例,其密鑰爲MediaStore.Audio.AudioColumns.ALBUM_ART,值爲file:///sdcard/yourartfile.png

警告:我沒有真的試過這個,所以它可能需要小小的調整。您可能需要更改文件的擴展名,以便Google將其視爲音頻文件而不是視頻文件,以便存在ALBUM_ART字段。可能還有其他一些我沒有考慮過的情況。

如果你絕對必須嵌入文件本身的藝術:

3GP文件不(據我所知)支持文件中嵌入隱蔽藝術的元數據。所以,你必須記錄到另一個容器格式。即使如此,我認爲唯一可用的支持隱藏藝術元數據的OutputFormat是MP4,並且我不知道任何Android功能允許您直接修改媒體文件以添加此類標記。