Cordova 3.5.0 - FAILED renaming / storage / emulated / 0 / tmprecording.3gp

I searched the web looking for others with similar problems. I found similar error messages, but no one found the answers. This looks like a general error message with both the Cordova 2.x and 3.x series versions. I get this error when I try to record audio using the Cordova org.apache.cordova.media plugin. In particular, after creating a media object that starts startRecord (), and then when I execute stopRecord (), that is, when an error occurs.

function recordJournalAudio() { var mediaRecFile = 'journalEntry-' + app.nextJournalID + '.amr'; if (!app.recording) { app.mediaRec = new Media(mediaRecFile, function() { console.log("recordAudio():Audio Success"); }, function(err) { console.log("recordAudio():Audio Error: "+ err.code); } ); $("#recordJournalAudioBtn").button("option", "theme", "b"); // Record audio app.mediaRec.startRecord(); app.recording = true; } if (app.recording) { app.mediaRec.stopRecord(); //THIS IS WHERE THE ERROR OCCURS $("#recordJournalAudioBtn").button("option", "theme", "a"); } } 

Does anyone have a suggestion on how to fix this?

+6
source share
1 answer

William is a bug / bug with implementation in the plugin. I looked through your question while I was looking for a solution for my own project.

The problem is that a temporary file is created initially to record audio, then it is moved and renamed after recording is completed. The used File.renameTo () function will not write from internal to SD (or vice versa). I rewrote this function for my purposes, and it works great as far as I can tell. Below is the updated feature.

https://github.com/apache/cordova-plugin-media/blob/master/src/android/AudioPlayer.java

org.apache.cordova.media> AudioPlayer.java Line 32 (add)

 import java.io.InputStream; import java.io.OutputStream; import java.io.FileOutputStream; import java.io.BufferedInputStream; import java.io.FileNotFoundException; 

org.apache.cordova.media> AudioPlayer.java Line 139 (replace)

 if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { this.audioFile = Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + file; } else { this.audioFile = "/data/data/" + handler.cordova.getActivity().getPackageName() + "/cache/" + file; } //this.audioFile = file; 

org.apache.cordova.media> AudioPlayer.java Line 168 (replace whole function)

 public void moveFile(String file) { /* this is a hack to save the file as the specified name */ File newf = new File(file); String folder = newf.getParent(); if (folder == null) folder = ""; File CheckDirectory; CheckDirectory = new File(folder); if (!CheckDirectory.exists()) { CheckDirectory.mkdir(); } String logMsg = "renaming " + this.tempFile + " to " + file; Log.d(LOG_TAG, logMsg); InputStream in = null; try { in = new BufferedInputStream(new FileInputStream(this.tempFile)); } catch (FileNotFoundException e) { //e.printStackTrace(); Log.e(LOG_TAG, "FAILED to open INPUT stream: " + logMsg); } OutputStream out = null; try { out = new FileOutputStream(file); } catch (FileNotFoundException e) { //e.printStackTrace(); Log.e(LOG_TAG, "FAILED to open OUTPUT stream: " + logMsg); } // Transfer bytes from in to out byte[] buf = new byte[1024]; int len; try { while ((len = in.read(buf)) > 0) out.write(buf, 0, len); in.close(); out.close(); } catch (IOException e) { //e.printStackTrace(); Log.e(LOG_TAG, "FAILED COPY: " + logMsg); } } 

Let me know if this takes care of your problem.

+3
source

Source: https://habr.com/ru/post/972513/


All Articles