Sound not playing in Phonegap app after changing to 3.1.0

我只是一个虾纸丫 提交于 2019-12-08 13:01:44

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!