In my Android app I am trying to record audio through the phone's mic, play it back, store it on Parse.com. The ultimate goal is to then allow other devices to stream the audio file.
I can successfully record the audio - here's how I do it: (the format is specified as .3gpp here, but .wav has been working for me too)
mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
AudioRecordTest();
mRecorder.setOutputFile(mFileName);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
"mFileName" is set here:
mFileName = Environment.getExternalStorageDirectory().getAbsolutePath();
mFileName += "/audiorecordtest.3gpp";
I can also play the file back. That works fine. Then I try to save it to Parse as a Parse File, and attach it to a Parse Object. Like so:
byte[] data = mFileName.getBytes();
ParseUser currentUser = ParseUser.getCurrentUser();
String usernameText = currentUser.getUsername();
String mUploadName = usernameText + "_recording.3gpp";
ParseFile file = new ParseFile(mUploadName, data);
file.saveInBackground();
ParseObject audioRecordings = new ParseObject("AudioRecording");
audioRecordings.put("Submitter", usernameText);
audioRecordings.put("AudioFile.3gpp", file);
audioRecordings.put("PositiveScore", 0);
audioRecordings.put("Negativescore", 0);
audioRecordings.put("Parent", currentUser);
audioRecordings.saveInBackground();
Now, I can see the Object and File on Parse.com's data browser. If I click on the audio file, I am taken to a audio player (so Parse recognizes it as audio, at least), but it won't play anything. So there's something wrong with the file.
Here's what I'm using to stream audio:
mPlayer = new MediaPlayer();
ParseQuery<ParseObject> query = ParseQuery.getQuery("AudioRecording");
query.getInBackground("YkfHDl2aEG", new GetCallback<ParseObject>() {
@Override
public void done(ParseObject recording, com.parse.ParseException e) {
if (e != null) { ... }
else {
ParseFile audioFile = recording.getParseFile("audioFile");
ParseFile audioFile = recording.getParseFile("audioFile");
String audioFileURL = audioFile.getUrl();
mPlayer = new MediaPlayer();
mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
try { mPlayer.setDataSource(audioFileURL); }
Then, I play the sound. I know I've got that part right because if I replace audioFileURL with this "http://www.pocketjourney.com/downloads/pj/tutorials/audio.mp3", it works fine. It's the Parse.com URL that's breaking it. This is the logcat error:
08-05 01:15:12.620: E/WVMExtractor(55): Failed to open libwvm.so
08-05 01:15:12.620: E/MediaPlayer(875): error (1, -2147483648)
This is tough to debug because apparently it corresponds to this unhelpful error: MediaPlayer.MEDIA_ERROR_UNKNOWN. (according to this question Android MediaPlayer error (1, -2147483648))
Any advice would be appreciated! Thanks