playing audio file

66 views
Skip to first unread message

Nick Allan

unread,
Apr 2, 2016, 4:50:31 AM4/2/16
to greasemon...@googlegroups.com
Hi all
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
e.g
If I pre-load it using
// @require https://website.com/alert.wav

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.


var player = document.createElement('audio');
player.src = 'https://website.com/alert.wav';
player.preload = 'auto';
player.play();

Any suggestions welcome

Nick

Klaus Johannes Rusch

unread,
Apr 2, 2016, 4:55:48 PM4/2/16
to greasemon...@googlegroups.com
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/

Nick Allan

unread,
Apr 2, 2016, 10:24:01 PM4/2/16
to greasemon...@googlegroups.com
OK, thanks for that. will give it a go.
Reply all
Reply to author
Forward
0 new messages