Go2Holidays's Forum Posts

  • Ashley

    Did you discover any more with this? Does it work fine on Android for you?

    Thanks!

  • Ashley

    PhoneGap (mentioned in message above ;-) )

  • Ashley

    Hey Ashley, thanks for getting r85 out so quickly and for dealing with these issues.... :-)

    However.... can I confirm whether the audio is being properly suspended on Android when you switch out of the game to another application (or phone call, or home screen)....? I did a test on the Android Simulator using a PhoneGap built game exported from r85 and when I click the home button (to display phone's main home page) the action does indeed seem to pause (as it appears to be at the same place when I return to the game), but the audio just carried on playing....?

    The game has a main music track playing, with various sound effects being played as things happen. Obviously the sound effects stop as the action has stopped to keep generating them.... but the music kept playing.

    :-(

    Any ideas?

    Thanks!

  • Ashley

    I have another 'bug' with a game built with CS2, when exported as HTML5 and built as a BB PlayBook app (as a .bar file).

    Basically this uses the HTML5 audio object for the sound (I converted the sounds to mp3 and search replaced the refs to m4t etc in the JS to play mp3).

    Trouble is.... the game keeps setting the sound volume to MAX! You can alter the volume on the BB to be quite low.... then when you play the game it will reset back to max volume....

    Um... any idea why that might be? Anything that could be done about it??

    Thanks! :-)

    Ian

  • P.S. Not sure if you'll need to look into something similar for AppMobi export too......?

  • Hi Ashley,

    Thanks for the reply. Yes... I think I probably thought that at first too! But apparently not....

    And yes, you can get rejected... I'm pretty sure Apple identify such behaviour as meriting a rejection, and Amazon's US App store for Android apps reviews each app and require this area to work correctly. On phones the ability to be able to manage incoming calls without any interruption is treated pretty seriously. That even means that apps which can in any way cause the phone to actually hang could cause a rejection.

    But... I think a fix should be straightforward. The PhoneGap docs provide the details of the event handlers and it is simply a matter of using them, pausing all action and muting all the sound.

    Thanks! :-)

  • Wow.... so it does! Thanks for the tip. Here goes then...

    Ashley Hi, what do you think of my PhoneGap suggestion? :-)

  • Hi,

    I wonder if I could post a suggestion for a new feature (or fix) for CS2 please? (Or if it already handles this, then this is simply a question about how it's done....!)

    Basically, CS2's support of mobile gaming is improving every day, and the recent fixes to the PhoneGap audio support are very welcome. However, there's another side to mobile gaming which is somewhat crucial.... the need to pause the game (and particularly the audio) when an 'interrupting event' occurs on the phone - for example an incoming phone-call, or the user simply 'backing out' of the running game to access some other app.

    As far as I can see, currently CS2 games, exported to PG, and run on Android (for example), have their audio and gameplay continuing whenever the user 'pauses' the app or a phone-call comes in. This is problematic enough for various App stores to reject such a game (as it is crucial to deal with phone-call interruptions).

    Using PhoneGap it is quite easy to handle these incoming events, but it needs some code in the JS to listen to the events and respond to them, and whilst I could dive into the exported index.html and JS files generated by CS2 and add in some code to manage this.... ideally CS2 would simply handle the events and apply some code to silence the sound effects, and pause the game, whenever one of these events occurs (and restart it all when the user returns).

    The PhoneGap docs describe the events here:

    docs.phonegap.com/en/1.5.0/phonegap_events_events.md.html

    So... (Ashley in particular)... could this be something to add to a new CS build please? (Preferably ASAP... as it's a blocking issue with releasing mobile versions of CS2 games on iPhone/Android etc.)

    OR... if I've completely missed an existing feature within CS2 that handles such events, perhaps someone could simply point this numbskull in the right direction? :-)

    Thanks! (And my apologies if I've posted this in the wrong section... I'm happy to move it or repost)

    Ian

  • BTW... Call me Ian.

  • Go2Holidays - I think I've managed to fix audio in PhoneGap for the next build. Note that android_asset is specific to Android so it will break iOS, I've added an Android-specific check in my version. Also the Audio object has a pretty complicated caching/audio recycling engine which your code does not take in to account, I'd recommend waiting for the next build where it should work!

    Fantastic Ashley - sounds great. <img src="smileys/smiley4.gif" border="0" align="middle" />

    I was aware that my code was Android only (would have suggested a check for system for anyone else), and realised it might not 'handle everything', but I was simply attempting to make the CS code do what I needed. For now, it seems to work.....

    ....when you get it in the next build... well, problem solved!

    Good work.

  • Essentially.... the code which CS creates lacks that /android_assett/www/ part, so it won't find the files (will look on SD card instead).

    This article pointed that out:

    simonmacdonald.blogspot.com/2011/05/using-media-class-in-phonegap.html

    So I did...

    1. in the c2runtime.js file I found the new Media() call and made it thus:

    case API_PHONEGAP:

    this.instanceObject = new Media("/android_asset/www/" + buffer_.src);

    break;

    2. I also set the default api to be API_PHONEGAP (because on my tests it didn't detect properly)... so:

    var API_HTML5 = 0;

    var API_WEBAUDIO = 1;

    var API_PHONEGAP = 2;

    var API_APPMOBI = 3;

    var api = API_PHONEGAP;

    3. I made the hasEnded() function return true for PhoneGap (as it wasn't working in my trial)...

    So...

    C2AudioInstance.prototype.hasEnded = function ()

    {

    switch (this.myapi) {

    case API_HTML5:

    return this.instanceObject.ended;

    case API_WEBAUDIO:

    if (!this.fresh && !this.stopped && this.instanceObject["loop"])

    return false;

    return (audRuntime.kahanTime.sum - this.startTime) > this.buffer.bufferObject["duration"];

    case API_PHONEGAP:

    return true; //(audRuntime.kahanTime.sum - this.startTime) > this.buffer.bufferObject.getDuration();

    case API_APPMOBI:

    true;     // recycling an AppMobi sound does not matter because it will just do another throwaway playSound

    }

    4. And in this call, I added the test for phonegap to prevent it doing the usual action:

    instanceProto.tick = function ()

    {

    var i, len, a;

    for (i = 0, len = audioInstances.length; i < len; i++)

    {

    a = audioInstances;

    if (a.myapi !== API_HTML5 && a.myapi !== API_APPMOBI

         && a.myapi != API_PHONEGAP)

    // PHONEGAP bit added above...

    {

    if (!a.fresh && !a.stopped && a.hasEnded())

    {

    a.stopped = true;

    audTag = a.tag;

    audRuntime.trigger(cr.plugins_.Audio.prototype.cnds.OnEnded, audInst);

    }

    ....I also (I should add) made the audio files be mp3s (for my test) and searched and replaced the references to .ogg and .m4a to be .mp3

    This was all done in the NON-minified JS..... and all seems to work fine when built as an Android APK via PhoneGap.

    If others (eg. ranma) have already got this working, then that's great, but it wasn't working for me (and perhaps not for others) and this is what it took to fix it. So hopefully that's of help to someone. :-)

  • Good news... I managed to tweak CS2's JS to get it playing audio (multi channel) via PhoneGap on Android. I'll post again later (tonight maybe) with what I did, but hopefully it will be of help to others.

    <img src="smileys/smiley1.gif" border="0" align="middle" />

  • Aha... well that explains that one then. Thanks. So... CS + PhoneGap = NO sound.... and CS + AppMobi = Unstoppable sound.

    Which is a good comparison of the relative pros and cons of PG and AM in that area then.... and as such, I don't think we are, or were, off topic, were we? ;-)

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Hi,

    I've given AppMobi a whirl then... quite straightforward... although I did have one or two issues with it.

    But the main problem I noticed is that any calls to stop audio from CS seem to get ignored? This obviously may be an issue with CS, but I notice that whilst short sound simply play (and finish soon afterwards, so you have no real need to stop them), music just keeps on playing. It never stops! So when you go to another layout in your game which starts another music track, you simply have two tracks of music playing over the top of each other.

    Is this a known issue? Anyone else found that?

    Thanks!

  • Hi Ranma,

    Great - that's fantastic. I saw the XDK, but wasn't sure if that was one of the $99 a year for usage offerings. If it is simply a case of running in Chrome, and using it much as I'd use PhoneGap BUILD then I'll give it a go. Thanks! :-)