我能够录制和播放音频,但我想将我的音频文件存储在sqlite中。这是我用来录制音频的代码。
outputFile = Environment.getExternalStorageDirectory()。 getAbsolutePath()+" /myrecording.3gp" ;;;
myAudioRecorder = new MediaRecorder();
myAudioRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
myAudioRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
myAudioRecorder.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB);
myAudioRecorder.setOutputFile(outputFile);
提前致谢
答案 0 :(得分:0)
您需要将文件转换为blob,然后将其存储在Sqlite数据库中。
FileInputStream fis = new FileInputStream(outputfile);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer =new byte[1024];
int read;
while ((read = fis.read(buffer)) != -1) {
baos.write(buffer, 0, read);
}
baos.flush();
byte[] fileByteArray = baos.toByteArray();
ContentValues cv = new ContentValues();
cv.put("filename", filename);
cv.put("blob", fileByteArray);
yourDB.insert(TABLE_NAME, null, cv);