[英]Cordova Media Plugin multiple audio dosent work
i am new to cordova i tired to find solution ,i have 20 sound into my app , when i run it the app run first clicked Audio only and ignore/reject another sounds Code: 我是Cordova的新手,我很想找到解决方案,我的应用程序中有20种声音,当我运行该应用程序时,该应用程序首先单击“仅音频”,然后忽略/拒绝其他声音代码:
document.addEventListener('deviceready', onDeviceReady, false);
function onDeviceReady() {
document.querySelector("#playMp3Mild").addEventListener("touchend", playMp3Mild, false);
document.querySelector("#stop").addEventListener("touchend", stopAudio, false);
document.querySelector("#pause").addEventListener("touchend", pauseAudio, false);
};
media = null;
mediaTimer = null;
function playMp3Mild(src) {
mp3URL = getMediaURL(src);
if(media === null){
media = new Media(mp3URL , null, mediaError);
}
media.setVolume(0.1);
media.play();
}
function stopAudio() {
if (media) {
media.stop();
}
clearInterval(mediaTimer);
mediaTimer = null;
}
function getMediaURL(s) {
if(device.platform.toLowerCase() === "android") return "/android_asset/www/" + s;
return s;
}
function mediaError(e) {
}
i try remove this line if(media === null)
it's work , but now i haved another problem , all audios working together in same time. 我尝试删除此行
if(media === null)
它起作用,但是现在我遇到了另一个问题,所有音频同时工作。 so sorry for my bad english i believe with the community will be more good 非常抱歉我的英语不好,我相信与社区会更好
You might want to try stopping the old media first because you overwrite the media variable and not stopping the old one. 您可能想先尝试停止旧媒体,因为您覆盖了媒体变量,而不是停止旧媒体。 Then also set he old media value to null so your if(media === null) statement will return true.
然后将旧媒体值设置为null,这样您的if(media === null)语句将返回true。 media.stop() does not make media equal to null.
media.stop()不会使媒体等于null。 Please try the following and tell us if that worked for you.
请尝试以下操作,并告诉我们是否适合您。
function playMp3Mild(src) {
mp3URL = getMediaURL(src);
stopAudio();
if(media === null){
media = new Media(mp3URL , null, mediaError);
}
media.setVolume(0.1);
media.play();
}
function stopAudio() {
if (media) {
media.stop();
}
clearInterval(mediaTimer);
media = null;
mediaTimer = null;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.