You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sh...@apache.org on 2018/06/22 09:54:48 UTC
[cordova-plugin-media] branch master updated: CB-12849: checking
mediaState in destroy method,
and moving file by stream when renameTo failing (#168)
This is an automated email from the ASF dual-hosted git repository.
shazron pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-plugin-media.git
The following commit(s) were added to refs/heads/master by this push:
new 86660dd CB-12849: checking mediaState in destroy method, and moving file by stream when renameTo failing (#168)
86660dd is described below
commit 86660dd7cb76c8c4c7dd5a73c091bb8eda2a08ba
Author: Kenichi Naito <fi...@gmail.com>
AuthorDate: Fri Jun 22 18:54:45 2018 +0900
CB-12849: checking mediaState in destroy method, and moving file by stream when renameTo failing (#168)
---
src/android/AudioPlayer.java | 42 ++++++++++++++++++++++++++++++++++++++++--
1 file changed, 40 insertions(+), 2 deletions(-)
diff --git a/src/android/AudioPlayer.java b/src/android/AudioPlayer.java
index 861421e..b40e281 100644
--- a/src/android/AudioPlayer.java
+++ b/src/android/AudioPlayer.java
@@ -130,7 +130,9 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
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;
}
@@ -197,8 +199,44 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
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 {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org