Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CB-12849: checking mediaState in destroy method, and moving file by stream when renameTo failing #168

Merged
merged 1 commit into from
Jun 22, 2018

Conversation

knight9999
Copy link
Contributor

@knight9999 knight9999 commented Jun 20, 2018

Platforms affected

android

What does this PR do?

Resolving recording audio issue.

  1. File.renameTo method used in AudioPlayer.java can not move file across partitions.
    Then I developed copying the file by using i/o stream when renameTo failing.

  2. media.stopRecord() in JS calls stopRecording in Java,
    However media.release() in JS also calls stopRecording in Java via destroy method.
    The second call of stopRecording overrides the audio file with empty.
    This PR prevents the unnecessary call of stopRecording.

What testing has been done on this change?

sample code is

var fileName = "test.aac";

var myMedia = {};
var myStatus = null;

function recordMedia(){
    myMedia = new Media(cordova.file.dataDirectory + fileName, function (msg) {
        console.log("Success:", msg);
    }, function (e) {
        console.error("Error:", e);
        myMedia.release();
        myStatus = Media.MEDIA_NONE;
    }, function (status) {
        console.info("Status:", status);
        myStatus = status;
        if (status == Media.MEDIA_STOPPED) {
          myMedia.release();
          myStatus = Media.MEDIA_NONE;
        }
    });

    myMedia.startRecord();
}

function stopMedia () {
    if (myStatus != Media.MEDIA_NONE) {
      if (myStatus != Media.MEDIA_STOPPED) {
        myMedia.stopRecord();
      }
    }
}

Checklist

  • Reported an issue in the JIRA database
  • Commit message follows the format: "CB-3232: (android) Fix bug with resolving file paths", where CB-xxxx is the JIRA ID & "android" is the platform affected.
  • Added automated test coverage as appropriate for this change.

@knight9999 knight9999 changed the title CB-12849: check state in destroy and move file by stream CB-12849: checking mediaState in destroy method, and moving file by stream when renameTo failing Jun 20, 2018
@knight9999
Copy link
Contributor Author

The travis CI errors are resolved by other PR #166 .

@shazron
Copy link
Member

shazron commented Jun 22, 2018

I've pulled in #166. Once https://travis-ci.org/apache/cordova-plugin-media passes can you rebase/merge from master to get the latest changes and push this up so the CI can re-run?

@shazron
Copy link
Member

shazron commented Jun 22, 2018

Looks like commit from master has passed, so feel free to rebase/merge this PR

@knight9999
Copy link
Contributor Author

Ok, I have rebased master.

@shazron shazron merged commit 86660dd into apache:master Jun 22, 2018
uaza pushed a commit to quiply/cordova-plugin-media that referenced this pull request Oct 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants