I want play my audio but I can't
I am encountering an issue with Cordova's Media plugin while attempting to play a sound in my mobile application. Currently, I am using Cordova version 12.0.0, macos 14 sonoma, with cordova plugin media 7.1 and Xcode version 15.
Here is the relevant code snippet:
function playAudio(src) {
var sv = SugarCube.State.variables;
if (!musica) {
if (sv.dispositivo == "ios") {
musica = new Media("sounds/" + src + ".mp3", null, null, function (status) {
if (status === Media.MEDIA_STOPPED) musica.play({ playAudioWhenScreenIsLocked: false });
});
musica.play({ playAudioWhenScreenIsLocked: false });
musica.setVolume("" + sv.vmusica);
} else {
SugarCube.SimpleAudio.tracks.add("music", "sounds/" + src + ".mp3");
musica = SugarCube.SimpleAudio.tracks.get("music");
musica.volume(sv.vmusica);
musica.play();
musica.loop(true);
}
} else {
stopAudio();
playAudio(src);
}
}
I am using Xcode 15 and Cordova 12.0.0, along with Cordova Lib 12.0.1 on macOS 14 Sonoma. Additionally, I'm utilizing Node.js v20 and Cordova Plugin Media version 7.0.
Interestingly, when using macOS 13.3 Ventura, Xcode 14.3, Cordova 11.0.0 with iOS 6.3, and Media Plugin 6.1, the code works correctly.
I'm considering three possible solutions:
- Decode audio to M4A to test if the issue is related to MP3.
- Attempt a downgrade to Cordova 11.0 and Cordova Plugin Media 6.1 with iOS 6.3.
- Remove the Media plugin, although I need it for personalized volume controls and fade in/fade out functionalities.
I suspect that the problem may be related to using an older Mac that is not compatible with macOS 14, as it relies on OpenCore. However, even when compiling on an iPhone SE 3rd generation, I still cannot play the sound.
I'm looking for assistance or insights into potential problems with Cordova Media Plugin 7.0 in Xcode 15 with Apache Cordova.
The Cordova Media Plugin v7 changed the way it parses filepaths and names. If you want to access files inside the www folder you now need to add a / at the start of the filepath.
Try
If the sounds directory is inside the www folder your mp3 should play back.
Check https://github.com/apache/cordova-plugin-media/pull/362 for details.