Open .mp3 at certain time and close after play

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
johnhill
Posts: 24
Joined: 25 Sep 2014, 18:46

Open .mp3 at certain time and close after play

02 Jan 2018, 08:24

Hi,

I would like to open .mp3 file, "Play my song", which is located in my D:\ drive. Currently using Potplayer to open all my media player. This song will be my alarm clock at 6:00am. When done, close the Potplayer. The song is about 3 minutes long.

Thank you.
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Open .mp3 at certain time and close after play

02 Jan 2018, 08:58

Code: Select all

ppPath := "...\podplayer.exe" ; TBA !!
SetTimer, KickMeLikeBeckham,% 1000*60   ; check every minute
Return

KickMeLikeBeckham:
FormatTime, CurrentTime,, HH:mm   ; hh:mm = 12h format | HH:mm = 24h format
If (CurrentTime = "06:00") {
   ToolTip % CurrentTime
   RunWait, %ppPath%  "D:\play my song.mp3", Hide, PID
   Process, Close,% PID
   ToolTip
   }
Return
Not tested.
johnhill
Posts: 24
Joined: 25 Sep 2014, 18:46

Re: Open .mp3 at certain time and close after play

03 Jan 2018, 02:23

Since I can open the mp3 directly. Not going to include ppPath.

Below is the code I currently using but it will continuously open the same file until the script is stopped.

Code: Select all

#persistent
SetTimer, CheckTime, 1000
Return

CheckTime:
FormatTime, CurrentTime,, HH:mm
If (CurrentTime = "06:00")
{
Run, "C:\(my file location)"
} 
Return
How can I change this?
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Open .mp3 at certain time and close after play

03 Jan 2018, 03:52

You're using Run instead of RunWait. Checking the time every second (1000ms) will probably open 60 concurrent instances of the same song at the time the condition is met, right? Correct me if I'm wrong but you seem to ignore that you'll open a separate podplayer instance with each iteration, so once a song has finished playing you'll end up with a still existing podplayer process??
johnhill
Posts: 24
Joined: 25 Sep 2014, 18:46

Re: Open .mp3 at certain time and close after play

03 Jan 2018, 07:01

Xtra wrote:You can use SoundPlay to play .mp3
Thank you. Will check it later. :)
johnhill
Posts: 24
Joined: 25 Sep 2014, 18:46

Re: Open .mp3 at certain time and close after play

03 Jan 2018, 07:50

@Bobo, now with this code, the script will only run once.The only reason I think it run multiple time is the checktime is 1000.

Code: Select all

#persistent
ppPath := "C:\(programme file)"
SetTimer, CheckTime, 1000*60
Return

CheckTime:
FormatTime, CurrentTime,, HH:mm
If (CurrentTime = "20:41")
{
Runwait, %ppPath% "D:\(my file location)\play my song.mp3"
} 
Return
Now figure how to set close after play. Cant seem to get it work. Please brief me the tooltip. Another thing is the script didn't close after opening the mp3.
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Open .mp3 at certain time and close after play

03 Jan 2018, 11:21

:D Do you switch off your clock once it rang if you want to use it the next day as well? That's why I haven't used :arrow: ExitApp. Best case it runs 24/7.
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: Open .mp3 at certain time and close after play

03 Jan 2018, 12:51

Stop the timer when you play the .mp3 and then turn it back on after:

Code: Select all

CheckTime:
FormatTime, CurrentTime,, HH:mm
If (CurrentTime = "20:41")
{
    SetTimer, CheckTime, Off
    Runwait, %ppPath% "D:\(my file location)\play my song.mp3"
    SetTimer, CheckTime, On
} 
johnhill
Posts: 24
Joined: 25 Sep 2014, 18:46

Re: Open .mp3 at certain time and close after play

03 Jan 2018, 18:31

Thanks @xtra, Bobo

Do want to close the potplayer not the timer. If successful writing this, I do want to turn it off at the week days though :) . Any idea what command I need for the tasks.
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Open .mp3 at certain time and close after play

03 Jan 2018, 18:44

Well, I've already posted a working code that does exactly what you've requested.
No idea what's your problem. Simply click on a command (eg. like :arrow: Process) within the code section of this thread to get further details.
Good luck.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Descolada, Mateusz53, peter_ahk, Rohwedder and 182 guests