On 2016-04-02 10:49, Nick Allan wrote:
> I've got a greasemonkey script that needs to play an audio file
> fairely regularly. Is there any way I can tell greasemonkey to play
> the audio from the local hard drive
You should be able to play audio files from local file:/// URLs as well.
> I've got the following code that currently plays the audio from a URL
> but it introduces a slight delay and I'd rather pre-load it locally if
> I can.
Pre-load the audio file when the script loads
var player = document.createElement('audio');
player.preload = 'auto';
player.src = '
https://website.com/alert.wav';
then only run player.play() when you want to play the sound. As long as
the audio file is cachable it should play without delay (tried this with
a sample file from
http://freewavesamples.com/ and the audio played
immediately).
--
Klaus Johannes Rusch
klaus...@atmedia.net
http://klausrusch.atmedia.net/