在Android中录制音频
我已录制3gp格式的音频,并将其保存在SD卡中..这是我的代码,它运行sucessfull ..我需要添加图像到该音频文件,以便添加的图像将是专辑封面&当我尝试播放从SD卡位置的android..like这个默认媒体播放器所记录的声音..在Android中录制音频
图片中显示的图像是专辑封面,我有把它给我录制的音频文件
/**
* 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
}
如果您只需要该文件在Android Media Player中展示艺术品,请考虑使用Google Content Provider添加专辑封面。在创建3GP文件后,使用MediaScannerConnection API对其进行扫描。将其添加到数据库后,您可以在您的活动或服务中使用ContentResolver
进行访问。 MediaScannerConnection将为您提供新创建的文件的URI。您可以尝试将您想要的新作品放置在SD卡上的某个位置。然后,致电:getContentResolver().udpate(uri, newArtContentValue, null, null)
。 newArtContentValue
是ContentValue
对象的一个实例,其密钥为MediaStore.Audio.AudioColumns.ALBUM_ART
,值为file:///sdcard/yourartfile.png
。
警告:我没有真的试过这个,所以它可能需要小小的调整。您可能需要更改文件的扩展名,以便Google将其视为音频文件而不是视频文件,以便存在ALBUM_ART字段。可能还有其他一些我没有考虑过的情况。
如果你绝对必须嵌入文件本身的艺术:
3GP文件不(据我所知)支持文件中嵌入隐蔽艺术的元数据。所以,你必须记录到另一个容器格式。即使如此,我认为唯一可用的支持隐藏艺术元数据的OutputFormat是MP4,并且我不知道任何Android功能允许您直接修改媒体文件以添加此类标记。