phonegap:未捕获ReferenceError:未定义媒体 [英] phonegap: Uncaught ReferenceError: Media is not defined

查看:56
本文介绍了phonegap:未捕获ReferenceError:未定义媒体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在phonegap应用程序中播放声音.

I'm trying to play sounds in my phonegap application.

我用来执行此操作的功能如下:

The function I use to do so looks as follows:

function playAudio(src) {
   src = "media/sounds/" + src; //go to sound folder always

   if (device.platform == 'Android') {
        src = '/android_asset/www/' + src;  // Android needs the search path explicitly specified
   }

    var mediaRes = new Media(src,
        function onSuccess() {
            mediaRes.release(); // release the media resource once finished playing
        },
        function onError(e){
            alert("error playing sound: " + JSON.stringify(e) + "\n src: " + src);
        });

        mediaRes.play(); // the actual playing
}

奇怪的是,如果我设置一个仅包含index.html文件的应用程序,该文件的主体部分具有javascript,则声音有效.

The strange thing is, if I set up an app which only consists of the index.html file that has javascript in its body part, the sound works.

但是,当我使用一位同事编码的菜单时,它不起作用.在这种情况下,我得到

However, it does not work when I use the menu a colleague coded. In that case, I get

Uncaught ReferenceError: Media is not defined

要在两种设置(简单的一种工作菜单和一种菜单)之间进行切换,我只需交换包含文件的"www"文件夹.因此,cordova-plugin-media可以相同的方式用于两者. 对于不工作的用户,绝对可以使用cordova.js和phonegap.js(我在这些文件中包括了自定义警报功能以进行检查).

To switch between the two setups (the simple, working one and the menu one), I just exchange the "www" folder that contains the files. Thus, cordova-plugin-media is available for both in the same manner. For the not-working one, cordova.js and phonegap.js are definitely available (I included a custom alert function in those files to check).

另外,在发射"deviceready"之后执行声音播放.

Additionally, the sound playing is executed after "deviceready" has been fired.

有人建议在哪里继续调试吗?完全重新设计菜单可能会起作用,但是我想尽可能避免这种情况.

Does anyone have suggestions where to continue debugging? Completely redesigning the menu would probably work, but I want to avoid that if possible in any way.

推荐答案

更新:解决方案是在index.html中同时加载phonegap.js和cordova.js显然引起了冲突.删除phonegap.js并保留cordova.js可以解决问题.

Update: The solution was that loading both phonegap.js and cordova.js in the index.html apparently caused a conflict. Removing phonegap.js and leaving cordova.js did the trick.

这篇关于phonegap:未捕获ReferenceError:未定义媒体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆