I am building an app for IOS and Android using Meteor. It is designed for children so sound effects are a necessity.
So far I have tried the following, none of which have resulted in a simple .wav file playing while running the app on an actual iPhone:
-
adej:Meteor-Sound atmosphere package - Did not work, „MeteorSound not defined" error. https://atmospherejs.com/adej/meteor-sounds
-
Buzz.js - Worked perfectly in browser, did not work on the iPhone. (No error in xCode console)
-
cordova-plugin-media - Take a look at the following code, and the error that follows:
2.1. On a click event, the following is fired in a Template.home.events js file:
if (Meteor.isCordova) {
var test = playSound('/assets/audio/blop2.wav');
test.play();
}
2.2. The playSound() function is the following, defined in a globalFunctions.js doc client side:
playSound = function(sound) {
if (Meteor.isCordova) {
return new Media(
getMediaUrl(sound),
function (success) {
// success
},
function (err) {
// error
}
);
}
}
2.3. This calls the following getMediaUrl() function which takes the sound file and modifies it for a Cordova file structure:
getMediaUrl = function(sound) {
if (Meteor.isCordova) {
return cordova.file.applicationDirectory.replace('file://', '') + 'www/application/' + sound.substr(1);
}
} else {
return sound;
}
}
Okay, so far so good. But when launch this on my iPhone with the Meteor run ios-device, and click the button which should play the sound stored in my Public folder, I get the following error:
Unkown f*in Resource…
For reference, this Stack Overflow question was my guiding light:
Has anyone managed to get a sound to play in a Meteor-Cordova app? And if so, how did you do it? Am I doing something fundamentally stupid?