Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Support for WebAudioPlugin on PhoneGap-Apps #37

Closed
wants to merge 1 commit into from

Conversation

olsn
Copy link

@olsn olsn commented Mar 9, 2013

In PhoneGap Apps the location.protocol equals 'file:', however the Web Audio does not require XHR if used through PhoneGap, so I added an additional Line to check if this is a Mobile device.

Note

I did ONLY test this on an iPad since I do not have any other devices for testing.

@lannymcnie
Copy link
Member

This is great! Thanks for the pull. We will test it out, and integrate it shortly.

@OJayRobinson
Copy link
Contributor

Hi, thanks for this helpful post. Part of our future plans is better support for other platforms like PhoneGap.

One problem we have with your current solution is that it will disable local testing on mobile devices. Although this seems an unlikely scenario, we'd prefer a PhoneGap specific solution.

Some quick searching lead us to a couple of solutions. Specifically it seemed like one of the following would work:

var isMobilePhoneGap = window.device ? true : false; 
var isMobilePhoneGap = (cordova || PhoneGap || phonegap) ? true : false; 
function isPhoneGap() {
    return (cordova || PhoneGap || phonegap) 
    && /^file:\/{3}[^\/]/i.test(window.location.href) 
    && /ios|iphone|ipod|ipad|android/i.test(navigator.userAgent);
}

We don't currently have experience with PhoneGap, so we were wondering what you thought. Will any of these address the issue you were having, and if so which do you think is best? We really appreciate any feedback you can give us. Thanks.

@olsn
Copy link
Author

olsn commented Mar 12, 2013

window.device and (cordova || PhoneGap || phonegap) are all part of the PhoneGap-API, those are only active if the phonegap.js is included, however it is possible(and also quite common) to just use Phonegap as a Packaging-instrument, without including the phonegap.js.
I used the term 'Phonegap' instead of 'WebView', since this would be the technology that probably most people will use to quickly create a native App that packages and renders HTML-files ect.
But basically this applies for any WebView as they are sandboxed and won't throw a "cross domain" issue(for iOS, I'm not 100% sure about Android).

So the only solution that I can think of right now is via the userAgent - there are some ways to distinguish between WebView and Safari, but is it even possible to open a local file through Safari Mobile? (I couldn't find any way to distinguish the Android WebView from its Browser)

One problem we have with your current solution is that it will disable local testing on mobile devices.

The current status of the WebAudioPlugin is disabled for ANY local execution/testing, my solution does enable local execution/testing on mobile devices. (or did I mix something up here?)

@OJayRobinson
Copy link
Contributor

Thanks for the follow up.

Sorry, I should have been more clear. The WebAudioPlugin disables itself locally to allow for local testing of files (usually by allowing SoundJS to default to HTMLAudioPlugin). So, for example, you can use toolkit to output a project and pop it open in Chrome and have it work, without having to use a local web server. This scenario is unlikely on current mobile devices, but we try not add limits when possible. Does that make sense?

Perhaps a different approach, detecting if XHR is available? Although you say web audio does not require XHR when used through phonegap? Do you have any thoughts on this?

@olsn
Copy link
Author

olsn commented Mar 12, 2013

Now I got you :) - that does make sense!

When packaging assets with an application(like in PhoneGap), they will be called through the local-file:// protocol and the thing is that WebView-applications(like PhoneGap) are sandboxed, that's why "local" files will cause no cross-domain issue and that's why the WebAudio-Plugin will just work fine with "file://" through PhoneGap.

One "solution"(that only works on iOS though...) would be to detect if the environment is a WebView or the Mobile Browser, like here for iOS. But the User-Agents for Android the Android WebView seem to be almost identical (depending on some devices and version numbers) (see here).

I did quite some research and the only solution that made sense to me was to check for ios/android in the user-agent, because without that, both, the WebAudioPlugin and the HTMLAudioPlugin weren't working when i packaged the app with PhoneGap.

@OJayRobinson
Copy link
Contributor

Thanks a lot for your feedback it's been very helpful in figuring this out. We've decided to implement your solution as it seems more likely code would be running inside a PhoneGap app then locally on mobile devices.

Just a side note, HTMLAudioPlugin is disabled on iOS devices by default because of the limits of the system. You can read details in the documentation.

@olsn
Copy link
Author

olsn commented Mar 13, 2013

Glad I could be of some help to you :)
Yes I know about those limitations.

@lannymcnie
Copy link
Member

We have pushed support for local files, so I am going to close this for now. Please feel free to respond or re-open if issues persist.

@lannymcnie lannymcnie closed this Jul 24, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants