Phonegap / AppMobi pros and cons

Discussion and feedback on Construct 2

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

Post » Thu Feb 23, 2012 11:55 am

[code]    var myaudio = new Media("/android_asset/www/media/someSound.ogg");
    myaudio.play();[/code]
using call javascript plugin? :)
B
81
S
50
G
10
Posts: 555
Reputation: 13,009

Post » Thu Feb 23, 2012 12:12 pm

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:
http://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. :-)Go2Holidays2012-02-23 12:12:40
B
6
S
2
G
3
Posts: 17
Reputation: 2,383

Post » Thu Feb 23, 2012 3:52 pm

...interesting, I'll have a go at implementing this tonight, fingers crossed!
Due to the sound issues, I'm reluctantly using AppMobi at the moment, but don't like the way they lock me into releasing apps as 3.4.0. I can't use my own signing keys either, which is a pain.
Also, with PhoneGap I can decompile the apk and monkey around with the manifest file (and other files) then recompile with no problems. Can't seem to do the same with AppMobi.
B
31
S
11
G
7
Posts: 197
Reputation: 6,682

Post » Thu Feb 23, 2012 4:46 pm

@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!
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,478

Post » Thu Feb 23, 2012 5:02 pm

Kickass!
B
31
S
11
G
7
Posts: 197
Reputation: 6,682

Post » Thu Feb 23, 2012 8:12 pm

[QUOTE=Ashley] @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![/QUOTE]

Fantastic Ashley - sounds great.

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

Post » Thu Feb 23, 2012 8:12 pm

BTW... Call me Ian.
B
6
S
2
G
3
Posts: 17
Reputation: 2,383

Post » Fri Feb 24, 2012 7:38 am

On topic, regarding the permissions on Android (PhoneGap vs AppMobi).

On PhoneGap, if you add the "permissions=none" to the config file (which IIRC is the default when exporting now), then although the developer page on android market says that your users will be warned about 3 or 4 permissions, actually I found that when I installed my app on my phone through the market I was only prompted about 1 permission, which was "Full internet access" (which is something most ad-supported free apps have anyway so it won't shock the users). Compare that to the access of contacts data and such.

You actually do get prompted about 3-4 permissions IF you have the APK and install it directly, but if you do it through the market, it's only 1 permission prompt.
B
14
S
5
G
7
Posts: 235
Reputation: 5,175

Post » Fri Feb 24, 2012 9:51 am

Is AppMobi the right direction to go?

I'm asking this cause I tried to play with this cool environment and somehow I got this notion out of the creators of AppMobi - These people are hungry for money.

Don't get me wrong, every person who creates something which serves others needs to be able earn from his hard work, but in this case I got the feeling they plan to make impossible demands in this area.

I could be wrong but in the past I was right in many cases so I wanted to share this feeling with you just as a warning sign.

My fear is that they will do something like:
- $50 per year for DirectCanvas
- $49.95 if you want to play more than 2 sounds
- $40 for speeding up things with the new something
- $20.43 if you wish to get GeoLocation

I don't want to offend anyone but this is a personal feeling I got while working with this cool environment. Am I wrong? I really hope so.
It would be a shame for all of us if we'll reach cool results with C2/AppMobi only to find out it leads to unreasonable prices just for creating an app or two for the iOS market.
Add to this the yearly $99 apple asks and you have a path which 99% of the people here won't allow themselves to walk in.
B
35
S
12
G
6
Posts: 111
Reputation: 7,087

PreviousNext

Return to Construct 2 General

Who is online

Users browsing this forum: Colludium, MrMaciej and 1 guest