问题
I have a phonegap app that plays sound when you click and icon. It worked fine before I upgraded my phonegap build version from 2.9.0 to 3.1.0 (ios 7 build support).
Here is my code
//Play Audio
function playAudio(src) {
if (device.platform == 'Android') {
src = '/android_asset/www/' + src;
}
var media = new Media(src, success, error_error);
// Set Volume
media.setVolume('0.7');
media.play();
}
function success() {
// Default the icon
$('#sound-icon').removeClass('sound-icon-active').addClass('sound-icon-default');
//Ga tracking
ga_storage._trackEvent('Sound Played', 'Play', 'Sound Played succesfully.');
}
The code mysteriously stopped working. Could i be missing something here or is there something that changed in the iOS SDK
EDIT : I resolved the issue according to input from Dawson Loudon , in phonegap 3.x you have to include different plugins to access device specific features. In my case I needed to add the following:
to the config.xml.
Hope this helps someone else.
回答1:
When moving from PhoneGap 2.x to 3.x the biggest change is that all of the APIs are broken into separate plugins. This means that any device specific API needs to be installed as a plugin.
Looking at your code, you will need the device and media plugins installed.
For PhoneGap Build add this to config.xml:
<gap:plugin name="org.apache.cordova.device" version="0.2.8" />
<gap:plugin name="org.apache.cordova.media" version="0.2.8" />
For CLI run these commands (and rebuild or prepare):
(sudo) cordova plugin add org.apache.cordova.device
(sudo) cordova plugin add org.apache.cordova.media
来源:https://stackoverflow.com/questions/22669724/sound-not-playing-in-phonegap-app-after-changing-to-3-1-0