Audio alarm: Difference between revisions

Added Sidef
m (Removed manual categories)
(Added Sidef)
Β 
(43 intermediate revisions by 30 users not shown)
Line 1:
{{draft task}}
'''AudioAlarm''' is a program that asks the user to enter a certain number, representing a number of seconds. After the user enters the number, the program will ask the user to enter the name of an MP3 audio file (without the .mp3 file extension). The program will then display a (usually blank) page. After the time (indicated by the number) is up, a sound (indicated by the MP3 file) will go off. Useful for timers and alarm clocks. The app must be installed in its own folder, preferrably with a name like ''AudioAlarm''. To install a sound on the app, just copy the MP3 to the app folder you set up. Then, when the app asks you for the filename, you just type in the name without an extension.
 
=={{header|JavaScript}}==
=={{header|AutoHotkey}}==
'''WARNING! THIS APP IS NOT PURE JAVASCRIPT. IT IS MOSTLY HTML, WITH JAVASCRIPT FRAGMENTS IN IT.'''
Uses Run for maximum compatibility
<lang JavaScript>
<syntaxhighlight lang="ahk">Inputbox, seconds, Seconds, Enter a number of seconds:
<title> AudioAlarm </title>
FileSelectFile, File, 3, %A_ScriptDir%, File to be played, MP3 Files (*.mp3)
<script> var a=prompt("Enter a number of seconds", "");
Sleep Seconds*1000
var b=prompt("Enter the name of an MP3 file you have installed in the directory (without the .mp3 file extension)", "");
RunWait % file</syntaxhighlight>
document.write("<meta http-equiv='refresh' content='"+a+";url="+b+".mp3'>") </script></lang>
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
# syntax: GAWK -f AUDIOALARM.AWK
BEGIN {
printf("enter seconds to wait: ")
getline seconds
if (seconds !~ /^[0-9]+$/ || seconds > 99999) {
print("error: invalid")
exit(1)
}
printf("enter filename to play: ")
getline music_filename
if (music_filename ~ /^ *$/) {
print("error: invalid")
exit(1)
}
if (toupper(music_filename) !~ /\.(MID|MOV|MP[34]|WAV|WMA)$/) {
music_filename = music_filename ".MP3"
}
system(sprintf("TIMEOUT /T %d",seconds))
system(sprintf("START \"C:\\PROGRAM FILES\\WINDOWS MEDIA PLAYER\\WMPLAYER.EXE\" \"%s\"",music_filename))
exit(0)
}
</syntaxhighlight>
 
=={{header|Batch File}}==
<syntaxhighlight lang="dos">
@echo off
 
:: Get user input
:: %alarm% can have spaces, but cannot have quotation marks ("")
:: %time% has a working range of -1 to 99999 seconds
:input
set /p "time=Input amount of time in seconds to wait: "
set /p "alarm=Input name of alarm: "
 
:: Check if %time% is an integer with 'set /a'
set /a intcheck=%time%
if %intcheck%==0 goto input
 
cls
timeout /t %time% /nobreak >nul
start "" "%alarm%.mp3"
</syntaxhighlight>
{{out}}
<pre>
Input amount of time in seconds to wait: 5
Input name of alarm: alarm name with spaces
</pre>
=={{header|Delphi}}==
{{libheader| System.SysUtils}}
{{libheader| Bass}}
'''Bass''' is a third part library, free for non-commercial use, can be found here [https://www.un4seen.com]. Require a '''bass.dll''' in the same folder of executable.
<syntaxhighlight lang="delphi">
program AudioAlarm;
 
{$APPTYPE CONSOLE}
 
uses
System.SysUtils,
Bass;
 
procedure Wait(sec: Cardinal; verbose: Boolean = False);
begin
while sec > 0 do
begin
if verbose then
Writeln(sec);
Sleep(1000); // 1s
dec(sec);
end;
end;
 
function QueryMp3File: string;
begin
while True do
begin
Writeln('Enter name of .mp3 file to play (without extension) : ');
Readln(Result);
Result := Result + '.mp3';
if not FileExists(Result) then
begin
Writeln('The file "' + Result + '" not exist');
Continue;
end;
Break;
end;
end;
 
function QueryIntNumber(): Integer;
var
val: string;
begin
Result := 0;
repeat
Writeln('Enter number of seconds delay > 0 : ');
Readln(val);
 
if not TryStrToInt(val, Result) then
begin
Writeln('"', val, '" is not a valid number.');
Continue;
end;
if Result <= 0 then
begin
Writeln('"', val, '" must be greater then 0');
Continue;
end;
until Result > 0;
end;
 
function CreateMusic(MusicName: string): HSTREAM;
var
buffer: PChar;
begin
buffer := pchar(MusicName);
 
// Initialize audio - default device, 44100hz, stereo, 16 bits
if not BASS_Init(-1, 44100, 0, 0, nil) then
Writeln('Error initializing audio!');
 
Result := BASS_StreamCreateFile(False, buffer, 0, 0, 0{$IFDEF UNICODE} or
BASS_UNICODE {$ENDIF});
if Result = 0 then
Writeln('Error on load music!');
end;
 
procedure Play(Music:HSTREAM);
begin
if not BASS_ChannelPlay(Music, True) then
Writeln('Error playing music!');
end;
 
var
Music: HSTREAM;
MusicName: string;
delay: Cardinal;
 
begin
MusicName := QueryMp3File;
delay := QueryIntNumber;
Music := CreateMusic(MusicName);
 
Wait(delay, True);
 
Play(Music);
 
Readln;
BASS_StreamFree(Music);
BASS_Free();
end.</syntaxhighlight>
{{out}}
<pre>Enter name of .mp3 file to play (without extension) :
AudioAlarm
Enter number of seconds delay > 0 :
10
10
9
8
7
6
5
4
3
2
1</pre>
 
=={{header|EchoLisp}}==
<syntaxhighlight lang="scheme">
(lib 'timer)
(lib 'audio)
 
(define (AudioAlarm)
(display "Time to wake-up" "color:red")
(audio-show) ;; show audio control
(audio-play) ;; play it
)
(define (task)
(define audio-file
(read-string "ring0" "audio-file name? ring0/ring1/ring2/dalida"))
(define seconds (read-number 3600 "countdown (seconds) ?"))
(audio-src (string-append "./sounds/" audio-file))
(at seconds 'seconds AudioAlarm))
 
;; out
(task)
 
11/2/2016 23:43:42 : AudioAlarm
Time to wake-up ;; + ... 🎼 🎢🎡🎢🎡
 
</syntaxhighlight>
 
 
=={{header|FreeBASIC}}==
<syntaxhighlight lang="freebasic">Dim As Long sec
Dim As String song
Input "Delay in seconds: ", sec
Input "MP3 to play as alarm: ", song
song &= ".mp3"
 
Sleep sec, 1
 
Dim As String exename = "wmplayer.exe"
Exec(exename, song)
 
Sleep</syntaxhighlight>
 
=={{header|FutureBasic}}==
FB has several audio/video play options from simple to professional. This demo code uses the simplest.
<syntaxhighlight lang="futurebasic">
 
include resources "Here Comes the Sun.mp3"
 
_window = 1
begin enum 1
_timerLabel
_timerField
_songLabel
_songField
_line
_timerBtn
end enum
 
begin globals
CFRunLoopTimerRef gTimer
NSInteger gCount
end globals
 
void local fn BuildWindow
NSUInteger i
CGRect r = fn CGRectMake( 0, 0, 400, 150 )
window _window, @"Audio Alarm", r, NSWindowStyleMaskTitled + NSWindowStyleMaskClosable + NSWindowStyleMaskMiniaturizable
r = fn CGRectMake( 5, 105, 195, 22 )
textlabel _timerLabel, @"Seconds until alarm:", r, _window
ControlSetAlignment( _timerLabel, NSTextAlignmentRight )
r = fn CGRectMake( 210, 108, 160, 22 )
textfield _timerField, YES, @"5", r, _window
ControlSetAlignment( _timerField, NSTextAlignmentLeft )
r = fn CGRectMake( 5, 72, 195, 24 )
textlabel _songLabel, @"Name of wake-up song:", r, _window
ControlSetAlignment( _songLabel, NSTextAlignmentRight )
r = fn CGRectMake( 210, 75, 160, 22 )
textfield _songField, YES, @"Here Comes the Sun", r, _window
ControlSetAlignment( _songField, NSTextAlignmentLeft )
r = fn CGRectMake( 30, 55, 340, 5 )
box _line,, r, NSBoxSeparator
for i = _timerLabel to _songField
ControlSetFontWithName( i, @"Menlo", 13.0 )
next
r = fn CGRectMake( 260, 13, 120, 32 )
button _timerBtn,,, @"Start timer", r, _window
end fn
 
local fn MyTimerCallback( t as CFRunLoopTimerRef )
window output _window
ControlSetIntegerValue( _timerField, gCount )
if ( gCount == 0 and gTimer != NULL )
TimerInvalidate( gTimer )
SoundRef alarmSound = fn SoundNamed( @"Here Comes the Sun" )
fn SoundPlay( alarmSound )
else
gCount--
end if
end fn
 
local fn StartTimer
gTimer = fn TimerScheduledWithInterval( 1, @fn MyTimerCallback, NULL, YES )
end fn
 
void local fn DoDialog( ev as long, tag as long, wnd as long )
select ( ev )
case _btnClick
select ( tag )
case _timerBtn : gCount = fn ControlIntegerValue( _timerField ) : fn StartTimer
end select
case _soundDidFinishPlaying : gCount = 5 : ControlSetIntegerValue( _timerField, gCount )
case _windowWillClose : end
end select
end fn
 
on dialog fn DoDialog
 
fn BuildWindow
 
HandleEvents
</syntaxhighlight>
{{output}}
[[File:Audio Alarm.png]]
 
 
=={{header|Go}}==
As Go does not have any audio support in its standard library, this invokes the SoX utility's 'play' command to play the required .mp3 file.
<syntaxhighlight lang="go">package main
 
import (
"bufio"
"fmt"
"log"
"os"
"os/exec"
"strconv"
"time"
)
 
func main() {
scanner := bufio.NewScanner(os.Stdin)
number := 0
for number < 1 {
fmt.Print("Enter number of seconds delay > 0 : ")
scanner.Scan()
input := scanner.Text()
if err := scanner.Err(); err != nil {
log.Fatal(err)
}
number, _ = strconv.Atoi(input)
}
 
filename := ""
for filename == "" {
fmt.Print("Enter name of .mp3 file to play (without extension) : ")
scanner.Scan()
filename = scanner.Text()
if err := scanner.Err(); err != nil {
log.Fatal(err)
}
}
 
cls := "\033[2J\033[0;0H" // ANSI escape code to clear screen and home cursor
fmt.Printf("%sAlarm will sound in %d seconds...", cls, number)
time.Sleep(time.Duration(number) * time.Second)
fmt.Printf(cls)
cmd := exec.Command("play", filename+".mp3")
if err := cmd.Run(); err != nil {
log.Fatal(err)
}
}</syntaxhighlight>
 
=={{header|Java}}==
<syntaxhighlight lang="java">import com.sun.javafx.application.PlatformImpl;
import java.io.File;
import java.util.Scanner;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
 
public class AudioAlarm {
 
public static void main(String[] args) throws InterruptedException {
Scanner input = new Scanner(System.in);
 
System.out.print("Enter a number of seconds: ");
int seconds = Integer.parseInt(input.nextLine());
 
System.out.print("Enter a filename (must end with .mp3 or .wav): ");
String audio = input.nextLine();
 
TimeUnit.SECONDS.sleep(seconds);
 
Media media = new Media(new File(audio).toURI().toString());
AtomicBoolean stop = new AtomicBoolean();
Runnable onEnd = () -> stop.set(true);
 
PlatformImpl.startup(() -> {}); // To initialize the MediaPlayer.
 
MediaPlayer player = new MediaPlayer(media);
player.setOnEndOfMedia(onEnd);
player.setOnError(onEnd);
player.setOnHalted(onEnd);
player.play();
 
while (!stop.get()) {
Thread.sleep(100);
}
System.exit(0); // To stop the JavaFX thread.
}
}</syntaxhighlight>
 
=={{header|JavaScript}}/{{header|HTML}}==
<syntaxhighlight lang="javascript"><title> AudioAlarm </title>
<script>
var a=prompt("Enter a number of seconds", "");
var b=prompt("Enter the name of an MP3 file you have installed in the directory (without extension)", "");
document.write("<meta http-equiv='refresh' content='"+a+";url="+b+".mp3'>")
</script></syntaxhighlight>
 
=={{header|Julia}}==
Works when the computer will play an MP3 file with the "play" command.
<syntaxhighlight lang="julia">print("Enter seconds to wait: ")
(secs = tryparse(Int, readline())) == nothing && (secs = 10)
 
print("Enter an mp3 filename: ")
soundfile = strip(readline())
 
match(r"\.mp3$", soundfile) == nothing && (soundfile = soundfile * ".mp3")
(filesize(soundfile) == 0) && (soundfile = "default.mp3")
 
sleep(secs)
run(`play "$soundfile"`)
</syntaxhighlight>
 
 
=={{header|Kotlin}}==
For this to work on Ubuntu, 'glib' and 'libav-tools' need to be installed on your system.
<syntaxhighlight lang="scala">// version 1.1.51
 
import javafx.application.Application
import javafx.scene.media.Media
import javafx.scene.media.MediaPlayer
import javafx.stage.Stage
import java.io.File
import java.util.concurrent.TimeUnit
 
class AudioAlarm : Application() {
 
override fun start(primaryStage: Stage) {
with (primaryStage) {
title = "Audio Alarm"
width = 400.0
height= 400.0
show()
}
TimeUnit.SECONDS.sleep(seconds)
soundAlarm()
}
 
private fun soundAlarm() {
val source = File(fileName).toURI().toString()
val media = Media(source)
val mediaPlayer = MediaPlayer(media)
mediaPlayer.play()
}
 
companion object {
fun create(seconds: Long, fileName: String) {
AudioAlarm.seconds = seconds
AudioAlarm.fileName = fileName
Application.launch(AudioAlarm::class.java)
}
 
private var seconds = 0L
private var fileName = ""
}
}
 
fun main(args: Array<String>) {
print("Enter number of seconds to wait for alarm to sound : ")
val seconds = readLine()!!.toLong()
print("Enter name of MP3 file (without the extension) to sound alarm : ")
val fileName = readLine()!! + ".mp3"
AudioAlarm.create(seconds, fileName)
}</syntaxhighlight>
 
Sample input:
<pre>
Enter number of seconds to wait for alarm to sound : 3
Enter name of MP3 file (without the extension) to sound alarm : alarm
</pre>
 
=={{header|Liberty BASIC}}==
LB can play wav files natively. Here we call the standard Windows Media Player for an MP3.
If not already running, this will add an extra delay...
It will error if the mp3 file does not exist in the specified path.
<syntaxhighlight lang="lb">nomainwin
 
prompt "Delay in seconds"; sec$
prompt "MP3 to play as alarm"; mp3$
f$ ="f:\"; mp3$; ".mp3"
 
timer val( sec$) *100, [done]
wait
 
[done]
timer 0
run "C:\Program Files\Windows Media Player\wmplayer.exe " +chr$(34) +f$ +chr$(34)
 
end</syntaxhighlight>
 
=={{header|Lua}}==
{{Trans|Ruby}}
luasdl2 and luafilesystem libraries required.
 
<syntaxhighlight lang="lua">SDL = require "SDL"
mixer = require "SDL.mixer"
lfs = require "lfs"
 
print("Enter a number of seconds: ")
sec = tonumber(io.read())
print("Enter the MP3 file to be played")
mp3filepath = lfs.currentdir() .. "/" .. io.read() .. ".mp3"
 
mixer.openAudio(44100, SDL.audioFormat.S16, 1, 1024)
Music = mixer.loadMUS(mp3filepath)
Music:play(1)
 
print("Press Enter to quit")
io.read()
</syntaxhighlight>
 
=={{header|Nim}}==
{{Trans|Go}}
<syntaxhighlight lang="nim">import os, strutils, terminal
 
var delay: int
while true:
stdout.write "Enter delay in seconds: "
stdout.flushFile()
try:
delay = stdin.readLine.strip().parseInt()
break
except ValueError:
echo "Error: invalid value."
except EOFError:
echo()
quit "Quitting.", QuitFailure
 
var filename: string
while true:
stdout.write "Enter mp3 file name (without extension): "
stdout.flushFile()
try:
filename = stdin.readLine
break
except EOFError:
echo ()
quit "Quitting.", QuitFailure
 
stdout.eraseScreen()
echo "Alarm will sound in $# second(s)...".format(delay)
os.sleep delay * 1000
stdout.eraseScreen()
if execShellCmd("play $#.mp3" % filename) != 0:
echo "Error while playing mp3 file."</syntaxhighlight>
 
=={{header|OCaml}}==
requires mpg123 to be installed.
 
<syntaxhighlight lang="ocaml">let rec wait n = match n with
| 0 -> ()
| n -> Sys.command "sleep 1"; wait (n - 1);;
 
Printf.printf "Please enter a number of seconds\n";;
let time = read_int ();;
 
Printf.printf "Please enter a file name\n";;
let fileName = (read_line ()) ^ ".mp3";;
 
wait time;;
Sys.command ("mpg123 " ^ fileName);;
</syntaxhighlight>
 
 
=={{header|Phix}}==
<!--<syntaxhighlight lang="phix">(notonline)-->
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\AudioAlarm.exw
-- ===========================
--
-- If duration is checked then eg 1:30 means "perform a 90s countdown",
-- when unchecked the input is treated as a time of day, so 1:30 means
-- "at half past one" (am, but you can enter pm, or 13:30), although a
-- "4" is bluntly ignored until you make it (say) "4pm" or "4:15". You
-- should always [un]check //before// entering anything, btw.
--</span>
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">dl</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">`Download rosetta\bass\ from http://phix.x10.mx/pmwiki/pmwiki.php?n=Main.Bass`</span>
<span style="color: #7060A8;">assert</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">get_file_type</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"bass"</span><span style="color: #0000FF;">)=</span><span style="color: #004600;">FILETYPE_DIRECTORY</span><span style="color: #0000FF;">,</span><span style="color: #000000;">dl</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">include</span> <span style="color: #000000;">bass</span><span style="color: #0000FF;">\</span><span style="color: #000000;">bass</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
<span style="color: #000000;">BASS_Init</span><span style="color: #0000FF;">(-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">44100</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">atom</span> <span style="color: #000000;">filePlayerHandle</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">BASS_StreamCreateFile</span><span style="color: #0000FF;">(</span><span style="color: #004600;">false</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">`bass\Scream01.mp3`</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">include</span> <span style="color: #000000;">pGUI</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
<span style="color: #008080;">include</span> <span style="color: #004080;">timedate</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
<span style="color: #004080;">Ihandle</span> <span style="color: #000000;">mainwin</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">clock</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">count</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">alarm</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">durat</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">vbox1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">timer</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">secfmts</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #008000;">"%d:%d:%d"</span><span style="color: #0000FF;">,</span> <span style="color: #000080;font-style:italic;">-- h:m:s</span>
<span style="color: #008000;">"%d:%d"</span><span style="color: #0000FF;">,</span> <span style="color: #000080;font-style:italic;">-- m:s</span>
<span style="color: #008000;">"%d"</span><span style="color: #0000FF;">},</span> <span style="color: #000080;font-style:italic;">-- s</span>
<span style="color: #000000;">pdsfmts</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #008000;">"hh:mm:ss pm"</span><span style="color: #0000FF;">,</span>
<span style="color: #008000;">"hh:mm:sspm"</span><span style="color: #0000FF;">,</span>
<span style="color: #008000;">"hh:mm pm"</span><span style="color: #0000FF;">,</span>
<span style="color: #008000;">"hh:mmpm"</span><span style="color: #0000FF;">,</span>
<span style="color: #008000;">"hh pm"</span><span style="color: #0000FF;">,</span>
<span style="color: #008000;">"hhpm"</span><span style="color: #0000FF;">,</span>
<span style="color: #008000;">"hh:mm:ss"</span><span style="color: #0000FF;">,</span>
<span style="color: #008000;">"hh:mm"</span><span style="color: #0000FF;">}</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">remain</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span> <span style="color: #000080;font-style:italic;">-- whole seconds (for both duration and at time),
-- with 0 meaning inactive/already triggered.</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">alarm_changed_cb</span><span style="color: #0000FF;">(</span><span style="color: #004080;">Ihandle</span> <span style="color: #000080;font-style:italic;">/*alarm*/</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">string</span> <span style="color: #000000;">txt</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupGetAttribute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">alarm</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"VALUE"</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">res</span>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">IupGetInt</span><span style="color: #0000FF;">(</span><span style="color: #000000;">durat</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"VALUE"</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">then</span>
<span style="color: #000080;font-style:italic;">-- duration in [[h:]m:]s format, eg 1:30 means perform a 90s countdown</span>
<span style="color: #000000;">remain</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">f</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">secfmts</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
<span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">scanf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">txt</span><span style="color: #0000FF;">,</span><span style="color: #000000;">secfmts</span><span style="color: #0000FF;">[</span><span style="color: #000000;">f</span><span style="color: #0000FF;">])</span>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">)=</span><span style="color: #000000;">1</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">res</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
<span style="color: #000000;">remain</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">remain</span><span style="color: #0000FF;">*</span><span style="color: #000000;">60</span><span style="color: #0000FF;">+</span><span style="color: #000000;">res</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">exit</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">else</span>
<span style="color: #000080;font-style:italic;">-- time of day in hh[:mm[:ss]][[ ]pm] format, eg 1:30 means "at half past one"</span>
<span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">parse_date_string</span><span style="color: #0000FF;">(</span><span style="color: #000000;">txt</span><span style="color: #0000FF;">,</span><span style="color: #000000;">pdsfmts</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">)!=</span><span style="color: #000000;">3</span> <span style="color: #008080;">then</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">today</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">date</span><span style="color: #0000FF;">()</span>
<span style="color: #000000;">res</span><span style="color: #0000FF;">[</span><span style="color: #004600;">DT_YEAR</span><span style="color: #0000FF;">..</span><span style="color: #004600;">DT_DAY</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">today</span><span style="color: #0000FF;">[</span><span style="color: #004600;">DT_YEAR</span><span style="color: #0000FF;">..</span><span style="color: #004600;">DT_DAY</span><span style="color: #0000FF;">]</span>
<span style="color: #000000;">remain</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">ceil</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">timedate_diff</span><span style="color: #0000FF;">(</span><span style="color: #000000;">today</span><span style="color: #0000FF;">,</span><span style="color: #000000;">res</span><span style="color: #0000FF;">))</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">remain</span><span style="color: #0000FF;"><</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span> <span style="color: #000000;">remain</span> <span style="color: #0000FF;">+=</span> <span style="color: #7060A8;">timedelta</span><span style="color: #0000FF;">(</span><span style="color: #000000;">days</span><span style="color: #0000FF;">:=</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">return</span> <span style="color: #004600;">IUP_DEFAULT</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">get_now</span><span style="color: #0000FF;">()</span>
<span style="color: #008080;">return</span> <span style="color: #7060A8;">format_timedate</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">date</span><span style="color: #0000FF;">(),</span><span style="color: #008000;">"hh:mm:sspm Dddd dth Mmmm yyyy"</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">timer_cb</span><span style="color: #0000FF;">(</span><span style="color: #004080;">Ihandle</span> <span style="color: #000080;font-style:italic;">/*timer*/</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">IupSetStrAttribute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">clock</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"TITLE"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">get_now</span><span style="color: #0000FF;">())</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">remain</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">remain</span> <span style="color: #0000FF;">-=</span> <span style="color: #000000;">1</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">remain</span><span style="color: #0000FF;">!=</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">hours</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">remain</span><span style="color: #0000FF;">/(</span><span style="color: #000000;">60</span><span style="color: #0000FF;">*</span><span style="color: #000000;">60</span><span style="color: #0000FF;">)),</span>
<span style="color: #000000;">seconds</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">remain</span><span style="color: #0000FF;">,</span><span style="color: #000000;">60</span><span style="color: #0000FF;">*</span><span style="color: #000000;">60</span><span style="color: #0000FF;">),</span>
<span style="color: #000000;">minutes</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">seconds</span><span style="color: #0000FF;">/</span><span style="color: #000000;">60</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">seconds</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">seconds</span><span style="color: #0000FF;">,</span><span style="color: #000000;">60</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">IupSetStrAttribute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">count</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"TITLE"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%02d:%02d:%02d"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">hours</span><span style="color: #0000FF;">,</span><span style="color: #000000;">minutes</span><span style="color: #0000FF;">,</span><span style="color: #000000;">seconds</span><span style="color: #0000FF;">})</span>
<span style="color: #008080;">else</span>
<span style="color: #7060A8;">IupSetStrAttribute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">count</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"TITLE"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">""</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">BASS_ChannelPlay</span><span style="color: #0000FF;">(</span><span style="color: #000000;">filePlayerHandle</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">return</span> <span style="color: #004600;">IUP_IGNORE</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #7060A8;">IupOpen</span><span style="color: #0000FF;">()</span>
<span style="color: #000000;">clock</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupLabel</span><span style="color: #0000FF;">(</span><span style="color: #000000;">get_now</span><span style="color: #0000FF;">(),</span><span style="color: #008000;">"EXPAND=HORIZONTAL"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">count</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupLabel</span><span style="color: #0000FF;">(</span><span style="color: #008000;">""</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"EXPAND=HORIZONTAL"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">alarm</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupText</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"VALUECHANGED_CB"</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">Icallback</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"alarm_changed_cb"</span><span style="color: #0000FF;">))</span>
<span style="color: #000000;">durat</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupToggle</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"duration"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"VALUE=ON, RIGHTBUTTON=YES"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">vbox1</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupVbox</span><span style="color: #0000FF;">({</span><span style="color: #7060A8;">IupHbox</span><span style="color: #0000FF;">({</span><span style="color: #7060A8;">IupLabel</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"Time:"</span><span style="color: #0000FF;">),</span><span style="color: #000000;">clock</span><span style="color: #0000FF;">}),</span>
<span style="color: #7060A8;">IupHbox</span><span style="color: #0000FF;">({</span><span style="color: #7060A8;">IupLabel</span><span style="color: #0000FF;">(</span><span style="color: #008000;">" Left:"</span><span style="color: #0000FF;">),</span><span style="color: #000000;">count</span><span style="color: #0000FF;">}),</span>
<span style="color: #7060A8;">IupHbox</span><span style="color: #0000FF;">({</span><span style="color: #7060A8;">IupLabel</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"Alarm:"</span><span style="color: #0000FF;">),</span><span style="color: #000000;">alarm</span><span style="color: #0000FF;">,</span><span style="color: #000000;">durat</span><span style="color: #0000FF;">},</span>
<span style="color: #008000;">"NORMALIZESIZE=VERTICAL"</span><span style="color: #0000FF;">)},</span>
<span style="color: #008000;">"NMARGIN=10x10,GAP=5"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">mainwin</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupDialog</span><span style="color: #0000FF;">(</span><span style="color: #000000;">vbox1</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">`TITLE="Audio Alarm", RASTERSIZE=320x125`</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">IupShow</span><span style="color: #0000FF;">(</span><span style="color: #000000;">mainwin</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">timer</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupTimer</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">Icallback</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"timer_cb"</span><span style="color: #0000FF;">),</span> <span style="color: #000000;">1000</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">IupMainLoop</span><span style="color: #0000FF;">()</span>
<span style="color: #7060A8;">IupClose</span><span style="color: #0000FF;">()</span>
<!--</syntaxhighlight>-->
 
=={{header|Pure Data}}==
(Pure Data really needed file upload: A screenshot of the patch would save space and at the same time be self-explanatory, thus making the script superfluous.)
 
'''Alarm.pd:'''
<pre>
#N canvas 623 244 351 664 10;
#X obj 18 19 cnv 15 310 30 empty empty empty 20 12 0 14 -203904 -66577 0;
#X obj 227 183 cnv 15 60 30 empty empty empty 20 12 0 14 -204786 -66577 0;
#X obj 18 433 cnv 15 310 36 empty empty empty 20 12 0 14 -203904 -66577 0;
#X floatatom 155 27 5 0 24 1 : h -;
#X floatatom 197 27 5 0 59 1 : - -;
#X floatatom 239 27 5 0 59 1 hh:mm:ss - -;
#X obj 155 63 * 3600;
#X obj 197 63 * 60;
#X obj 209 340 moses 1;
#X msg 209 375 Alarm;
#X obj 209 397 print;
#X floatatom 77 27 8 0 90000 0 duration duration -;
#X obj 155 107 +;
#X obj 200 129 +;
#X obj 239 63 change;
#X msg 239 85 bang;
#X obj 239 107 s h;
#X obj 197 85 int;
#X obj 35 293 metro 1000;
#X obj 35 340 int;
#X obj 75 340 - 1;
#X obj 35 196 bng 15 250 50 0 empty empty start -7 -7 0 10 -204786 -1 -13381;
#X msg 98 246 stop;
#X obj 98 196 bng 15 250 50 0 empty pause pause -7 -7 0 10 -261234 -1 -86277;
#X obj 158 196 bng 15 250 50 0 empty empty resume -10 -7 0 10 -262130 -1 -83269;
#X obj 62 246 int;
#X obj 100 375 > 0;
#X obj 158 246 int;
#X obj 200 152 s duration;
#X obj 35 216 t b b;
#X text 133 28 <-;
#X floatatom 231 196 8 0 0 2 countdown countdown_in countdown_out;
#X obj 35 397 s countdown_in;
#X obj 209 318 r countdown_out;
#X obj 36 484 openpanel;
#X obj 129 575 readsf~;
#X obj 162 626 dac~;
#X msg 129 506 1;
#X obj 246 565 loadbang;
#X obj 36 449 bng 15 250 50 0 empty select select -10 -7 0 10 -262130 -1 -1;
#X obj 122 449 bng 15 250 50 0 empty empty test -4 -7 0 10 -204786 -1 -1;
#X obj 181 449 hsl 100 15 0 1 0 0 empty volume volume -2 -7 0 10 -261682 -1 -1 4950 0;
#X obj 163 600 *~;
#X text 72 438 ALARM;
#X text 72 449 SOUND;
#X obj 129 484 t b b;
#X msg 36 506 set open \$1;
#X obj 294 449 bng 15 250 50 0 empty empty off -1 -7 0 10 -261234 -1 -1;
#X msg 294 506 0;
#X msg 246 587 \; pd dsp 1 \; volume 0.5 \; select 1;
#X msg 36 528 open *.wav;
#X connect 3 0 6 0;
#X connect 4 0 7 0;
#X connect 4 0 14 0;
#X connect 5 0 13 1;
#X connect 5 0 14 0;
#X connect 6 0 12 0;
#X connect 7 0 17 0;
#X connect 8 0 9 0;
#X connect 8 0 22 0;
#X connect 8 0 45 0;
#X connect 9 0 10 0;
#X connect 11 0 25 1;
#X connect 12 0 13 0;
#X connect 13 0 28 0;
#X connect 14 0 15 0;
#X connect 15 0 16 0;
#X connect 17 0 12 1;
#X connect 18 0 19 0;
#X connect 19 0 20 0;
#X connect 19 0 26 0;
#X connect 19 0 32 0;
#X connect 20 0 19 1;
#X connect 21 0 29 0;
#X connect 22 0 18 0;
#X connect 23 0 22 0;
#X connect 24 0 27 0;
#X connect 25 0 19 1;
#X connect 26 0 27 1;
#X connect 27 0 18 0;
#X connect 29 0 18 0;
#X connect 29 1 25 0;
#X connect 33 0 8 0;
#X connect 34 0 46 0;
#X connect 35 0 42 0;
#X connect 35 1 45 0;
#X connect 37 0 35 0;
#X connect 38 0 49 0;
#X connect 39 0 34 0;
#X connect 40 0 45 0;
#X connect 41 0 42 1;
#X connect 42 0 36 0;
#X connect 42 0 36 1;
#X connect 45 0 37 0;
#X connect 45 1 50 0;
#X connect 46 0 50 0;
#X connect 47 0 48 0;
#X connect 48 0 35 0;
#X connect 50 0 35 0;
</pre>
'''Features:'''
* Pd has built-in WAV file support - mp3 will require an extension
* Time input by hours, minutes and seconds
* Start, pause and resume button
* Sound file selection via file browser dialog, test button and volume control
 
=={{header|Python}}==
Python natively supports playing .wav files (via the [https://docs.python.org/3.4/library/wave.html wave] library), but not .mp3. Therefore, this calls to the OS to start the file. This behaves as though the mp3 file were double-clicked and plays the file with the default system player.
 
{{works with|Python|3.4.1}}
 
<syntaxhighlight lang="python">import time
import os
 
seconds = input("Enter a number of seconds: ")
sound = input("Enter an mp3 filename: ")
 
time.sleep(float(seconds))
os.startfile(sound + ".mp3")</syntaxhighlight>
 
=={{header|Racket}}==
Racket does not currently have native mp3 support so this example uses system to call an external application.
<syntaxhighlight lang="racket">#lang racket
(display "Time to wait in seconds: ")
(define time (string->number (read-line)))
 
(display "File Name: ")
(define file-name (read-line))
 
(when (file-exists? (string->path (string-append file-name ".mp3")))
(sleep time)
(system* "/usr/bin/mpg123" (string-append file-name ".mp3")))</syntaxhighlight>
 
=={{header|Raku}}==
requires mpg123 to be installed.
<syntaxhighlight lang="raku" line># 20221111 Raku programming solution
 
loop (my $wait; $wait !~~ Int;) { $wait=prompt('enter seconds to wait: ') }
 
loop (my $mp3='';!"$mp3.mp3".IO.e;) { $mp3=prompt('enter filename to play: ') }
 
run '/usr/bin/clear';
 
sleep($wait);
 
run '/usr/bin/mpg123', "$mp3.mp3";</syntaxhighlight>
 
=={{header|REXX}}==
===using SLEEP===
<syntaxhighlight lang="rexx">/*REXX pgm to prompt user for: # (of secs); a name of a MP3 file to play*/
 
say '──────── Please enter a number of seconds to wait:'
parse pull waitTime .
/*add code to verify number is a valid number. */
 
say '──────── Please enter a name of an MP3 file to play:'
parse pull MP3FILE
/*add code to verify answer is a valid filename.*/
 
call sleep waitTime
MP3FILE'.MP3'
/*stick a fork in it, we're done.*/</syntaxhighlight>
'''output''' when using the input of: <tt> xxx </tt>
 
===using spin===
<syntaxhighlight lang="rexx">/*REXX pgm to prompt user for: # (of secs); a name of a MP3 file to play*/
 
say '──────── Please enter a number of seconds to wait:'
parse pull waitTime .
 
say '──────── Please enter a name of an MP3 file to play:'
parse pull MP3FILE
 
call time 'Reset' /*reset the REXX (elapsed) timer.*/
 
do until time('E') >waitTime /*wait out the clock (in seconds)*/
end
 
MP3FILE'.MP3'
/*stick a fork in it, we're done.*/</syntaxhighlight>
 
=={{header|Ring}}==
<syntaxhighlight lang="ring">
# Project : AudioAlarm
 
load "stdlib.ring"
see "Delay in seconds: "
give sec
see "MP3 to play as alarm: "
give mp3
f = mp3 + ".mp3"
sleep(sec)
system("C:\Ring\wmplayer.exe C:\Ring\calmosoft\" + f)
</syntaxhighlight>
Output:
 
[https://www.dropbox.com/s/9l5fef83wj61zw5/AudioAlarm.avi?dl=0 AudioAlarm]
 
=={{header|Ruby}}==
requires mpg123 to be installed.
 
<syntaxhighlight lang="ruby">puts "Enter a number of seconds:"
seconds = gets.chomp.to_i
puts "Enter a MP3 file to be played"
mp3filepath = File.dirname(__FILE__) + "/" + gets.chomp + ".mp3"
sleep(seconds)
pid = fork{ exec 'mpg123','-q', mp3filepath }
</syntaxhighlight>
 
=={{header|Sidef}}==
Requires mpg123 to be installed.
<syntaxhighlight lang="ruby">var seconds = Sys.read("Enter a number of seconds: ", Number)
var mp3filepath = Sys.read("Enter a MP3 file to be played: ", File)+".mp3"
Sys.sleep(seconds)
Sys.run('mpg123', '-q', mp3filepath)</syntaxhighlight>
 
=={{header|Tcl}}==
{{libheader|Snack}}
<syntaxhighlight lang="tcl">package require sound
 
fconfigure stdout -buffering none
puts -nonewline "How long to wait for (seconds): "
gets stdin delay
puts -nonewline "What file to play: "
gets stdin soundFile
 
snack::sound snd
snd read $soundFile
after [expr {$delay * 1000}] {snd play -command {set done 1}}
vwait done
 
catch {snd stop}
snd destroy
puts "all done"
exit</syntaxhighlight>
 
=={{header|Wren}}==
{{libheader|DOME}}
The number of seconds to wait and the alarm filename are passed as command line arguments rather than being requested individually.
 
Currently, DOME can only playback .wav and .ogg files so we use the former here.
<syntaxhighlight lang="wren">import "dome" for Window, Process, Platform
import "graphics" for Canvas, Color
import "audio" for AudioEngine
 
var StartTime = Platform.time
 
class AudioAlarm {
construct new() {
Window.title = "Audio alarm"
}
 
init() {
var args = Process.args
if (args.count != 4) {
System.print("Two arguments should be passed at the command line, viz:")
System.print(" dome audio_alarm.wren <seconds to wait> <wav filename without extension>")
System.print("Exiting DOME")
Process.exit()
}
_secs = Num.fromString(args[2])
_wav = args[3] + ".wav"
Canvas.print("Alarm will sound in %(_secs) seconds...", 10, 10, Color.white)
AudioEngine.load("alarm", _wav)
_alarmed = true
}
 
update() {
var currTime = Platform.time
if (_alarmed && (currTime >= StartTime + _secs)) {
AudioEngine.play("alarm")
_alarmed = false
Canvas.cls()
Canvas.print("Alarm has sounded", 10, 10, Color.white)
}
}
 
draw(alpha) {}
}
 
var Game = AudioAlarm.new()</syntaxhighlight>
 
=={{header|XPL0}}==
Works on Raspberry Pi.
<syntaxhighlight lang="xpl0">int Time, I, J, Ch;
char FN(80), Ext;
[Text(0, "Number of seconds to wait? ");
Time:= IntIn(0);
Text(0, "Name of mp3 file to play? ");
I:= 0;
loop [Ch:= ChIn(0);
if Ch = \CR\$0D then quit;
FN(I):= Ch;
I:= I+1;
];
Ext:= ".mp3";
for J:= 0 to 3 do
FN(I+J):= Ext(J);
ChOut(0, $0C); \blank screen with form feed
DelayUs(Time * 1_000_000);
PlaySoundFile(FN);
]</syntaxhighlight>
 
=={{header|Yabasic}}==
<syntaxhighlight lang="yabasic">input "How long to wait for (seconds): " sec
input "What file to play: " song$
wait sec
song$ = song$ + ".mp3"
 
system("explorer " + song$)
exit 0</syntaxhighlight>
 
=={{header|zkl}}==
There is no built in sound support so this example is coded for my Linux box.
A change: rather than seconds to wait, a time is used.
<syntaxhighlight lang="zkl">hms :=Time.Date.parseTime(ask("Time to play mp3 file: "));
file:=ask("File to play: ") + ".mp3";
 
time:=Time.Clock.localTime.copy();
time[3]=hms[0]; time[4]=hms[1]; time[5]=hms[2];
time=Time.Clock.mktime(time.xplode()) - Time.Clock.time;
 
println("Play ",file," in ",time," seconds");
Thread.Timer(System.cmd.fp("mplayer "+file),time).go(); // a thread
Atomic.sleep(time+1); // veg out until sound plays, then exit
//to just play the file, no threads:
//Atomic.sleep(time);
//System.cmd("mplayer "+file);
</syntaxhighlight>
{{out}}
<pre>
$ zkl ding
Time to play mp3 file: 8:23pm
File to play: ding
Play ding.mp3 in 45 seconds
<45 seconds pass>
MPlayer2 UNKNOWN (C) 2000-2012 MPlayer Team
...
Exiting... (End of file)
$
</pre>
2,747

edits