Hi Ashley,
I'm new here, but I'd like to ask about the PhoneGap audio issues... you wrote:
"I've tried, and failed, to get PhoneGap to play audio. It just doesn't support it AFAIK. AppMobi specifically provide an alternative way to play audio which I've plugged in to the Audio object, which is why it works. It would be nice if PhoneGap could play audio, but to be honest after a few months watching what they're doing and trying to prod them in to better supporting games, they just don't appear to be interested. I think they're more about supporting website-style apps. Their open source model also makes it hard to contact anyone in charge or get a clear status on what their plans are. I really like PhoneGap, but it's just not progressing fast enough. AppMobi are doing loads on the other hand, and things like playMobi look really good, which is why we're shifting focus - PhoneGap support is about as good as it can be right now."
I've not had time to investigate in-depth the JS which CS generates, but I see it attempts to access the PhoneGap media object to play sound, if running via PhoneGap. It 'ought' to work.
I did an experiment with a construct2 game I made. In the index.html page (which has the canvas on it) I added a standard HTML link to a test.html page. On that page I made some simple use of the PhoneGap media object (as described in PhoneGap's docs) to play some audio. I built this and deployed on the Android emulator on the PC. When run, the first page (the CS game) produced no audio.... but clicking the link to the test page then played the audio via PhoneGap's code just fine. So... the code CAN run in this app, it is just that the CS JS must be doing something a little out of kilter.
Here's the code in that test.html file I linked to...(taken straight out of the PG docs)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Media Example</title>
<script type="text/javascript" charset="utf-8" src="phonegap.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for PhoneGap to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// PhoneGap is ready
//
function onDeviceReady() {
playAudio("http://audio.ibeat.org/content/p1rj1s/p1rj1s_-_rockGuitar.mp3");
}
// Audio player
//
var my_media = null;
var mediaTimer = null;
// Play audio
//
function playAudio(src) {
if (my_media == null) {
// Create Media object from src
my_media = new Media(src, onSuccess, onError);
} // else play current audio
// Play audio
my_media.play();
// Update my_media position every second
if (mediaTimer == null) {
mediaTimer = setInterval(function () {
// get my_media position
my_media.getCurrentPosition(
// success callback
function (position) {
if (position > -1) {
setAudioPosition((position) + " sec");
}
},
// error callback
function (e) {
console.log("Error getting pos=" + e);
setAudioPosition("Error: " + e);
}
);
}, 1000);
}
}
// 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;
}
</script>
</head>
<body>
<a href="#" class="btn large" onclick="playAudio('http://audio.ibeat.org/content/p1rj1s/p1rj1s_-_rockGuitar.mp3');">Play Audio</a>
<a href="#" class="btn large" onclick="pauseAudio();">Pause Playing Audio</a>
<a href="#" class="btn large" onclick="stopAudio();">Stop Playing Audio</a>
<p id="audio_position"></p>
</body>
</html>