Sound in webapps
I just finished added some audio feedback to the EDI scanning stations. We do everything through an intranet site, which makes scanning very portable (although moving the barcode printer takes some work). One of the main problems is getting audio feedback when scanning. The scanner chirps when it reads, but there’s no audio from the web app that the scan went through.
I’ve been playing around with Soundmanager2, and finally got it working the way I want. I ended up adding a hack to it so I don’t have to adjust my original code. I included sound.js:
/*
* Use soundManager to play a sound
* (like an error) without hitting race condition
* between document ready and soundmanager onload.
* Just eval(error_sound) whenever you want to play it
*
* Be sure to include soundmanager2.js from /js/ folder
*/
var error_sound = '';
var warning_sound = '';
soundManager.url = '/js/swf/';
soundManager.debugMode = false;
soundManager.onready(function(oStatus) {
if (oStatus.success) {
var mysound = soundManager.createSound ({
id: "ping",
url: "/js/swf/ping.mp3"
});
var mysound2 = soundManager.createSound ({
id: "warning",
url: "/js/swf/warn.mp3"
});
}
})
soundManager.onload = function() {
error_sound = 'soundManager.play("ping")';
warning_sound = 'soundManager.play("warning")';
}
I just added eval(error_sound); to my original code wherever I want to play an audio cue. If sound manager loaded OK it plays, otherwise it just fails silently.