The Astral Pulse
News: Acceptable Use Policy for the forums. Please read and ensure that you respect these policies. Thank you.

If you wish the join The Astral Pulse, please create an account and then email myself or one of the moderators your username and email address (do not send us your password please) and we will activate your account for you. 
If it's been over 24 hours and you still haven't been approved, please send another email, we are just people too and sometimes we get busy.

We apologize for any inconveniences this may cause, but it's the last resort we have to fighting the spam for now.
Welcome, Guest. Please login or register. December 07, 2021, 14:20:28

Login with username, password and session length

Pages: [1]   Go Down
Author Topic: javascript to play an audio file every 20 minutes... after initial 4 hour delay  (Read 4232 times)
Astral Energy 1
Offline Offline

Posts: 19

View Profile Email
« on: November 05, 2018, 17:11:35 »

Maybe this counts as "writing"... saw in another thread someone was looking to play an audio file every 20 minutes after an initial 4 hour delay. This was my attempt at it...

<!DOCTYPE html>
Author: Smertrios
Date: November 5, 2018
Purpose: javascript for delays and sound files. this script
(after editing) will wait 4 hours then start playing an audio
file every 20 minutes. check the comments for information on
how to edit.

Note: its more complicated than it looks because of "policies"
which are basically hidden rules secretely imposed on new
scripters to make life more difficult by forcing the scripter
to search for reasons why the "simple" script they have typed
in is not working.

For instance I had to add a start button so there would be
"interaction with the page" before playing a sound file and how
the element reference returned by getElementById was defined
at the "global" level before it could be used in a function.

Rumor has it that "one does not simply play... an audio file"

How to use this script?

create a directory with this file saved as test.html and 2 other
audio files named testing.wav and audio1.wav. When you open
test.html in your browser and click the start button it will
play testing.wav to show that audio is working and then start
playing audio1.wav every 20 minutes (after a 4 hour delay *and*
after this file has had the delays I used for testing changed)

<button onclick="fn0()" type="button">Start</button> Reload page to "STOP"<br>

<h1 id="timer">Time: 0:0:0</h1>

<audio id="testing" controls>
<source src="testing.wav" type="audio/wav">

<audio id="audio1" controls>
<source src="audio1.wav" type="audio/wav">

var counter=0;

var hours=function(t){return t*minutes(60);}
var minutes=function(t){return t*seconds(60);}
var seconds=function(t){return t*1000;}

var testing=document.getElementById("testing");
var fn0=function(){
// change to hours(4) for 4 hour delay
document.body.innerHTML+=counter+" initial 4 hour delay started<br>"
// make sure audio is working by playing a "test" sound;
document.body.innerHTML+=counter+" playing \"testing\" sound file<br>";

var fn1=function(){
document.body.innerHTML+=counter+" initial 4 hour delay finished<br>"

var audio1=document.getElementById("audio1");
var fn2=function(){
// change to minutes(20) for a 20 minute delay
document.body.innerHTML+=counter+" playing \"audio1\" every 20 minutes<br>"

var Timer=0;
var onTimer=function()
var temp=Timer;
var hours=Math.floor(temp/3600);
var minutes=Math.floor(temp/60);
var seconds=temp;
var ele=document.querySelector('#timer');
ele.innerHTML='Time: '+hours+':'+minutes+':'+seconds;

Do you think coding subforum would have a place here?
The Astral Pulse

Pages: [1]   Go Up
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines
SMFAds for Free Forums

The Astral Pulse Copyright 2002 - 2014
Valid XHTML 1.0! Valid CSS! Dilber MC Theme by HarzeM