【问题标题】:How to store 3gp audio file in sqlite android如何在sqlite android中存储3gp音频文件
【发布时间】:2014-07-24 16:21:32
【问题描述】:

我可以录制和播放音频,但我想将音频文件存储在 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);

提前致谢

【问题讨论】:

  • 你真的想把文件中的数据放到db中,而不是仅仅使用db来跟踪当前文件的存在吗?
  • 兄弟你能把文件存入数据库吗?我需要帮助

标签: android sqlite


【解决方案1】:

你需要将文件转换成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);

【讨论】:

    猜你喜欢
    • 2020-09-08
    • 2013-11-01
    • 2015-06-26
    • 1970-01-01
    • 2011-12-16
    • 2013-04-26
    • 2021-02-11
    • 2016-07-16
    • 2016-04-20
    相关资源
    最近更新 更多