为什么MediaRecorder输出文件被切断

时间:2012-02-25 00:57:36

标签: android python google-app-engine

我有一个非常简单的活动来使用MediaRecorder录制音频。基本启动/停止功能

// start
recorder.prepare();
recorder.start();

// stop
recorder.stop();
recorder.release();
recorder = null;

我通过Blob数据存储区中的org.apache.http.client.methods.HttpPost将输出文件传递给Google App Engine。

// AsyncTask doInBackground
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(DEV_SERVER);
ByteArrayOutputStream outstream = new ByteArrayOutputStream();
MultipartEntity reqEntity = new MultipartEntity(
    HttpMultipartMode.BROWSER_COMPATIBLE);
ContentResolver cr = getContentResolver();

InputStream audio_is = cr.openInputStream(working_uri);
int nRead;
byte[] data = new byte[16384];
while ((nRead = audio_is.read(data, 0, data.length)) != -1) {
    outstream.write(data, 0, nRead);
}
outstream.flush();
ByteArrayBody body = new ByteArrayBody(outstream.toByteArray(),
    POST_TEMP_FILENAME);
reqEntity.addPart("uploaded", body);
httppost.setEntity(reqEntity);
httpclient.execute(httppost);

结果是sdcard上的完整文件,但是当文件存储在服务器上时它已损坏。

有可能我没有正确读取字节数吗?或者更重要的是Google App Engine无法正确存储Blob?

这是接收python代码:

def post(self):
    entry = models.Entry()
    entry.content = db.Blob(self.request.get("uploaded"))
    entry.put();

1 个答案:

答案 0 :(得分:0)

结果一切正常。我的桌面播放器VLC没有正确解码文件。 AMR / 3GP音频非常糟糕。