简体   繁体   中英

Why Is MediaRecorder Output File Being Cut Off

I have a very simple Activity to record audio using MediaRecorder . Basic start/stop functions

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

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

I pass the output file to Google App Engine via org.apache.http.client.methods.HttpPost in a Blob datastore.

// 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);

The result is a full file on the sdcard, but when the file is stored on the server it is corrupt.

Is it possible I'm not reading the bytes correctly? Or is it more a matter of Google App Engine not storing the Blob correctly?

Here is the receiving python code:

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

Turns out everything was working just fine. It was my desktop player VLC that wasn't decoding the file correctly. AMR/3GP audio is horrible.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM