Phonegap / AppMobi pros and cons

Discussion and feedback on Construct 2

Post » Wed Feb 22, 2012 12:46 pm

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>
B
6
S
2
G
3
Posts: 17
Reputation: 2,383

Post » Wed Feb 22, 2012 12:52 pm

But.... obviously right now the PhoneGap audio via CS isn't working.

So, if AppMobi is the only route, could I just ask for a simple run-down of what is needed to get a game built based on AppMobi?

ie. I run CS.... and export to AppMobi. That gives me a folder of files on disk. What do I do next with that in order to build it into an Android or iOS package?

(If the question sounds dim, it is simply because when I visit AppMobi's site I see a whole slew of different products and services, some open-source, some paid, and it's a bit confusing trying to work out which you need to simply take a CS game and get an Android package built based on AppMobi)

Thanks for any help! :-)
B
6
S
2
G
3
Posts: 17
Reputation: 2,383

Post » Wed Feb 22, 2012 1:47 pm

@Go2Holidays you need to download appmobi xdk https://chrome.google.com/webstore/detail/onmkoldigcfmebcinpmineoadckalllb and install it in chrome as plugin, then it's quite straight forward, you run it, you add application project, you paste c2 exported files, you refresh project, you build project.ranma2012-02-22 13:47:37
B
81
S
50
G
10
Posts: 555
Reputation: 13,009

Post » Wed Feb 22, 2012 1:55 pm

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! :-)
B
6
S
2
G
3
Posts: 17
Reputation: 2,383

Post » Wed Feb 22, 2012 3:06 pm

well that's the problem with appmobi, on every step you'll see $something :) want to update your app to a newer version? pay us $something a month! want payments in your app? pay us! :)
B
81
S
50
G
10
Posts: 555
Reputation: 13,009

Post » Wed Feb 22, 2012 7:36 pm

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!
B
6
S
2
G
3
Posts: 17
Reputation: 2,383

Post » Wed Feb 22, 2012 7:43 pm

true, stop audio doesn't work.
also i noticed lately some problems with audio in appmobi.
now. back on topic? :Dranma2012-02-22 19:44:44
B
81
S
50
G
10
Posts: 555
Reputation: 13,009

Post » Wed Feb 22, 2012 8:34 pm

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? ;-)
B
6
S
2
G
3
Posts: 17
Reputation: 2,383

Post » Wed Feb 22, 2012 8:51 pm

now we're not ;) also appmobi = not working editable text box plugin in C2 so no login of any kind can be created.
B
81
S
50
G
10
Posts: 555
Reputation: 13,009

Post » Thu Feb 23, 2012 11:27 am

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.

Go2Holidays2012-02-23 11:27:48
B
6
S
2
G
3
Posts: 17
Reputation: 2,383

PreviousNext

Return to Construct 2 General

Who is online

Users browsing this forum: Bad Wolf, saiyadjin and 4 guests