[
https://issues.apache.org/jira/browse/CB-12849?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16520193#comment-16520193
]
ASF GitHub Bot commented on CB-12849:
-------------------------------------
shazron closed pull request #168: CB-12849: checking mediaState in destroy
method, and moving file by stream when renameTo failing
URL: https://github.com/apache/cordova-plugin-media/pull/168
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/src/android/AudioPlayer.java b/src/android/AudioPlayer.java
index 861421e7..b40e281e 100644
--- a/src/android/AudioPlayer.java
+++ b/src/android/AudioPlayer.java
@@ -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;
}
@@ -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 {
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> Media Plugin: Saves file not in indicated directory
> ---------------------------------------------------
>
> Key: CB-12849
> URL: https://issues.apache.org/jira/browse/CB-12849
> Project: Apache Cordova
> Issue Type: Bug
> Components: cordova-android, cordova-plugin-media
> Affects Versions: 6.5.0
> Environment: Device model: Nexus 5X
> Android version of device: 8.1.0
> Platform version: 7.1.0
> Cordova version: 8.0.0
> Cordova plugin media version: 5.0.1
> Reporter: Florian Pechwitz
> Priority: Major
> Labels: cordova-plugin-media
>
> I tried to build an application which records, stops the recording and then
> plays the recorded audio.
> The recording works fine but if I try to play the recorded audio I get error
> code 1. I found out that the recorded audio file was not in the directory but
> in a totally different directory
> (/storage/emulated/0/(tmprecording-1495618229386.3gp) with a different file
> name (tmprecording-1495618229386.3gp) and a different media type (video/3gpp)
> as indicated.
> I created a repo with a example application for this issue:
> https://github.com/Durzan666/cordova-plugin-media-demo
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]