I have created a sound app for Android using Cordova. Everything was perfect, at least in the Android Studio's emulator, until I found something strange happening while testing on a real device.
My app contains more than 100 sounds one second each. You click to play sounds till you get 32 clicks that play audios without problems. But starting from thirty-third (33rd) click I get a message error:
code: -19 message: undefined
I must mention that you can reply the previous clicked sounds that still work. But other sounds get the error above.
If I close and reopen the app, sounds that gave error work again until I get to 33rd click and start getting the error message even for sounds that used to work.
Here is the code I use to play my sounds:
// Wait for device API libraries to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// device APIs are available
//
function onDeviceReady() {
var my_media = new playAudio();
}
// Audio player
//
var my_media = null;
var mediaTimer = null;
// Play audio
//
my_media = {}; // init the play object
function playAudio(src, id) {
if (!my_media[id]) { // check if media already created
my_media[id] = new Media(src, onSuccess, onError);
}
my_media[id].play();
}
//playAudio('file:///android_asset/www/media/1.mp3');
// Pause audio
//
function pauseAudio() {
if (my_media) {
my_media.pause();
}
}
// Stop audio
//
function stopAudio() {
if (my_media) {
my_media.stop();
}
clearInterval(mediaTimer);
mediaTimer = null;
}
// onSuccess Callback
//
function onSuccess() {
console.log("playAudio():Audio Success");
}
// onError Callback
//
function onError(error) {
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}
// Set audio position
//
function setAudioPosition(position) {
document.getElementById('audio_position').innerHTML = position;
}
Any IDEA? thanks