我正在制作一个基于 HTML 的 Adobe AIR 应用程序,当用户将鼠标悬停在链接上时,我想在其中播放哔声。 mouseenter 事件由 jQuery 处理,然后调用一个函数。对于 Web,它使用 Web Audio API(由 Howl.js 提供支持),但由于 AIR 不支持该 API,我回退到使用 Flash API。
我目前拥有的是:
// if Adobe AIR
if (window.runtime){
var myChannel = new window.runtime.flash.media.SoundChannel();
var beep;
$('ul.menu a').on('mouseenter', function(){
// stop all sounds... (should I be stopping all sounds though?)
window.runtime.flash.media.SoundMixer.stopAll();
// set beep as a new sound
beep = new window.runtime.flash.media.Sound();
// load mp3
beep.load(new URLRequest('./assets/beep.mp3'));
// once file has loaded
beep.addEventListener(air.Event.COMPLETE, function(){
myChannel = beep.play();
});
});
// we're running in the browser
} else {
var sound = new Howl({
urls: ['./assets/beep.mp3', './assets/beep.ogg']
});
$('ul.menu a').on('mouseenter', function(){
sound.play();
});
}
但它不起作用...我做错了什么?
最佳答案
这个有效:
var myChannel = new window.runtime.flash.media.SoundChannel();
var beep;
$('a').on('mouseenter', function(){
// stop all sounds... (should I be stopping all sounds though?)
window.runtime.flash.media.SoundMixer.stopAll();
// set beep as a new sound
beep = new window.runtime.flash.media.Sound();
// load mp3
beep.load(new air.URLRequest('./assets/beep.mp3'));
// once file has loaded
beep.addEventListener(air.Event.COMPLETE, function(){
myChannel = beep.play();
});
});
但是你不需要 myChannel
并且可以调用 beep.play();
事实上你可以用三行来完成:
var beep = new air.Sound();
beep.load(new air.URLRequest('./assets/beep.mp3'));
beep.play();
关于javascript - 在 Adobe AIR HTML 应用程序中悬停时播放声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24576277/