Interrupting itunes playback - how to do it automagically
July 21, 2010 9:25 AM   Subscribe

I want to interrupt a playing itunes stream with another program's output. I already have many pieces in place, but I need to trigger itunes to shaddap. How to do?

My client is a coffee shop and has a large Muslim following. We want to have call to prayer announced over the sound system. The sound system in question is a PC with itunes installed. I've installed a piece of software called Athan from IslamicFinder that will announce Azan at the appropriate times. I've tried to contact them but no response.

So, what I want is:
- itunes is running a playlist
- Athan software says "stop! I need to play call to prayer"
- itunes pauses
- Call to prayer runs and completes
- itunes resumes.

I know I can script itunes, and I've tested that the itunes stop/start script is the right one for the job. The trick is how to tell it to do so.

It appears Athan uses windows media player to play call to prayer. Are there WMI events I could trap, and whats the best way to go about using them?

Any suggestions welcome!
posted by disclaimer to Computers & Internet (7 answers total)
So you just want to trigger an Applescript (to stop/start iTunes) when Athan does its thing, right? Sort of a hacky way to do this is to use Audio Hijack and set it to run a script when it detects any sound coming from the Athan program. I can't think of a better way to do it without having some access to what Athan is doing.

Alternative: Is Athan necessary? Are the times constant every day? You could definitely make your own script that plays a call-to-prayer MP3 at certain times, and interacts with iTunes as well.
posted by supercres at 9:59 AM on July 21, 2010

Oh, sorry. I noticed the "PC" part about ten seconds too late. There must be a PC program that runs like Audio Hijack: "Program X has sound output above threshold Y? Okay, run script Z!" I don't know specifics, though. Sorry.
posted by supercres at 10:01 AM on July 21, 2010

You can use the terminal command '/usr/bin/osascript /path/to/script.scpt' to execute the AppleScript that tells iTunes to stop/play call to prayer/start.

You could then use cron (pre OS 10.5) or launchd (OS 10.5 & later) to run osascript to run the call to prayer script at the designated intervals. Cron is pretty easy to configure "by hand", launchd considerably less so (IMHO) - but there is a launchd GUI called Lingon that's helpful.
posted by usonian at 10:02 AM on July 21, 2010

::sigh:: I'm sorry - I read your question through twice and still managed to miss the 'PC' part. I'm not familiar with COM scripting for iTunes, but theoretically the same strategy should work; have a an automated process call your script at the correct intervals. Maybe CRONw is worth a look?
posted by usonian at 10:05 AM on July 21, 2010

Are there WMI events I could trap, and whats the best way to go about using them?

Does a window pop up when Athan starts playing or anything like that? If there's something like that you can check for, AutoHotKey is probably the easiest way to write a script to do it. Windows API has some relatively easy-to-use functions for checking if a certain window is on the screen or not. Also AutoHotKey specifically has some more complex options like searching for certain colors on the screen, so if there's any sort of visual indication when the audio plays you may be able to write a script to detect it.
posted by burnmp3s at 10:16 AM on July 21, 2010

Frankly, I would install Linux or FreeBSD on the machine and run liquidsoap, which is a powerful (read: stepp learning curve) scriptable stream management package that allows for scheduled interruptions (such as station breaks and calls to prayer). I've Googled for miscellaneous Windows iTunes scripts and while I imagine it's possible to pause/restart or skip to a specific track, I haven't found the information for that yet.
posted by rhizome at 10:43 AM on July 21, 2010

A late response... we're going to give AutoHotKey a shot, it looks like it has a good chance of doing exactly what I want.

We can't use a cron job (or windows scheduled task) because the actual time of call to prayer varies from season to season and is based on a number of factors. It doesn't happen at the same times every day.

Thanks everyone for your responses!
posted by disclaimer at 2:11 PM on July 22, 2010

« Older [Translation Filter] A friend ...   |  Please help me find Beta tape ... Newer »
This thread is closed to new comments.