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; }
org.apache.cordova.media> AudioPlayer.java Line 168 (replace whole function)
public void moveFile(String file) { 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) {
Let me know if this takes care of your problem.
source share