0

I'm developing an app with angularJS and Cordova

Now I'm using the Media Plugin for play different audios

I detected and issue on iOs when I'm playing a background audio (long audio and looped) and another audio(short and plays only one time), when the second audio is finished, then my background audio also stops

any idea how to fix?

piece of code

backgroundMusic = new Media("background",
        function () {
            //success (object has completed the current play, record, or stop)
        },
        function (err) {
            //error
            console.log("playAudio():Audio Error: " + err);
        },
        function (status) {

            if(status == Media.MEDIA_STOPPED){
                //patch for ios issue
                backgroundMusic.seekTo(1);
                backgroundMusic._position = 0;
                //end of patch
                backgroundMusic.play({playAudioWhenScreenIsLocked : false});
            }
        }
    );
backgroundMusic.play({playAudioWhenScreenIsLocked : false});
//and the other audio
openPopUp = new Media("openPopUp.mp3",
        function () {
            //success (object has completed the current play, record, or stop)
        },
        function (err) {
            //error
            console.log("playAudio():Audio Error: " + err);
        }
    );

openPopUp.play({playAudioWhenScreenIsLocked : false});

When the openPopUp audio is finished, then the background audio ends too

3
  • Are you trying to play multiple Audio streams at the same time? I don't think you can do that with the Media Plugin. I've had better experience using this plugin: github.com/floatinghotpot/cordova-plugin-nativeaudio
    – johnborges
    Oct 21, 2016 at 19:04
  • @johnborges Yes I'am trying to play two audios, the background audio, and some times when user iteracts clicking some items another audio is playing, For use that plugin, nativeAudio I have to install the Angular service module? Thanks Oct 24, 2016 at 7:15
  • @johnborges It seems that is an error from Cordova media plugin, I found that: issues.apache.org/jira/browse/CB-7599 issues.apache.org/jira/browse/CB-11026 Oct 24, 2016 at 13:37

1 Answer 1

1

a PR has been made for this problem: "Fix CDVSound killing all audio when a single file finishes".

I test it and it fixes the issue. As Apache has no yet merge the PR, I had to fork the repo, include the fix and publish my own version. If you want to try it, replace the original cordova plugin with:

cordova add cordova-plugin-media-with-fix@5.0.1-dev-updated-with-fix-2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.