Skip to content

Commit

Permalink
CB-12849: checking mediaState in destroy method, and moving file by s…
Browse files Browse the repository at this point in the history
…tream when renameTo failing (#168)
  • Loading branch information
knight9999 authored and shazron committed Jun 22, 2018
1 parent 524c337 commit 86660dd
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions src/android/AudioPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ public void destroy() {
this.player = null;
}
if (this.recorder != null) {
this.stopRecording(true);
if (this.state != STATE.MEDIA_STOPPED) {
this.stopRecording(true);
}
this.recorder.release();
this.recorder = null;
}
Expand Down Expand Up @@ -197,8 +199,44 @@ public void moveFile(String file) {
if (size == 1) {
String logMsg = "renaming " + this.tempFile + " to " + file;
LOG.d(LOG_TAG, logMsg);

File f = new File(this.tempFile);
if (!f.renameTo(new File(file))) LOG.e(LOG_TAG, "FAILED " + logMsg);
if (!f.renameTo(new File(file))) {

FileOutputStream outputStream = null;
File outputFile = null;
try {
outputFile = new File(file);
outputStream = new FileOutputStream(outputFile);
FileInputStream inputStream = null;
File inputFile = null;
try {
inputFile = new File(this.tempFile);
LOG.d(LOG_TAG, "INPUT FILE LENGTH: " + String.valueOf(inputFile.length()) );
inputStream = new FileInputStream(inputFile);
copy(inputStream, outputStream, false);
} catch (Exception e) {
LOG.e(LOG_TAG, e.getLocalizedMessage(), e);
} finally {
if (inputStream != null) try {
inputStream.close();
inputFile.delete();
inputFile = null;
} catch (Exception e) {
LOG.e(LOG_TAG, e.getLocalizedMessage(), e);
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (outputStream != null) try {
outputStream.close();
LOG.d(LOG_TAG, "OUTPUT FILE LENGTH: " + String.valueOf(outputFile.length()) );
} catch (Exception e) {
LOG.e(LOG_TAG, e.getLocalizedMessage(), e);
}
}
}
}
// more than one file so the user must have pause recording. We'll need to concat files.
else {
Expand Down

0 comments on commit 86660dd

Please sign in to comment.