我正在开发一个音乐应用程序,如果我要进入可以播放声音的页面,请离开该页面,然后立即重新访问,我会收到此错误。 我用谷歌搜索了这个问题,但似乎根本找不到类似的东西。 我正在为我的应用程序使用 cordova 媒体播放器和 LowLatencyAudio 插件。 下面是指定页面上的代码和我收到的错误的图像。 任何帮助将不胜感激,因为我真的陷入困境了!
<div class="drum" id="bass" ontouchstart="play('bass');" ontouchend="touchEnd(event);">Bass</div>
<div class="drum" id="highhat" ontouchstart="play('highhat');" ontouchend="touchEnd(event);">High Hat</div>
<div class="drum" id="snare" ontouchstart="play('snare');" ontouchend="touchEnd(event);">Snare</div>
<div class="drum" id="bongo" ontouchstart="play('bongo');" ontouchend="touchEnd(event);">Bongo</div>
<script type="text/javascript">
var lla;
function onBodyLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
function onDeviceReady() {
if( window.plugins && window.plugins.LowLatencyAudio ) {
lla = window.plugins.LowLatencyAudio;
lla.preloadFX('assets/bass.mp3', 'assets/bass.mp3', function(msg){}, function(msg){ alert( 'Error: ' + msg ); });
lla.preloadFX('assets/snare.mp3', 'assets/snare.mp3', function(msg){}, function(msg){ alert( 'Error: ' + msg ); });
lla.preloadFX('assets/highhat.mp3', 'assets/highhat.mp3', function(msg){}, function(msg){ alert( 'Error: ' + msg ); });
lla.preloadFX('assets/bongo.mp3', 'assets/bongo.mp3', function(msg){}, function(msg){ alert( 'Error: ' + msg ); });
}
}
function play(drum) {
document.getElementById(drum).className = 'drum touched';
lla.play('assets/' + drum + '.mp3');
}
function touchEnd(event) {
event.target.className = 'drum';
}
</script>
Error: A reference already exists for the audio id.
最佳答案
看起来对于同一 Assets 多次调用 lla.preloadFX
存在问题。阅读插件文档和实际的 java 代码后,此错误是真正的警告/通知,而不是错误。我重新格式化了我的示例,以展示如何忽略此消息,因为它不会影响您的应用程序。
这是一个例子:
function onDeviceReady() {
if( window.plugins && window.plugins.LowLatencyAudio) {
lla = window.plugins.LowLatencyAudio;
lla.preloadFX('assets/bass.mp3', 'assets/bass.mp3', function(msg){}, function(msg){ if(msg != 'A reference already exists for the specified audio id.') { alert( 'Error: ' + msg ); } });
}
}
使用此代码,如果存在“真实”错误,您将看到错误,否则它将忽略有关已加载资源的消息。这应该可以解决问题。
关于javascript - "Error: A reference already exists for the specified id"如何隐藏/修复此警报?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22413326/