I have an eight field database of about 7,000 OTR audio files. In addition to using the database to manipulate and analyze the OTR catalog, I would like to be able initiate play of the selected audio file from within the database.
I can create a field with the local path+file name, but I cannot see a way to have Panorama X trigger that file to open in its native Quicktime player.
For me using openanything for a sound file will open iTunes to play it. If you want to be sure to play in in the QuickTime Player you would use the openwith statement. Here is an example that will open the QuickTime Player with the current sound listed in a field called theSounds:
openwith "QuickTime Player",theSounds
In QuickTime Player the sound does not auto-play and you have to manually play it. In iTunes the sound automatically plays when opened. If you want it to automatically play in the QuickTime Player you might have to try an AppleScript to get it done.
Wouldnât be cool if there was a âsoundâ verb in Panorama. For example, you could have a database with photos of different birds and when the form opened or the photo changed, a sound file of the bird call would play. Iâm sure Iâve seen something like that somewhere before. Seemed like a pretty neat feature.
A year ago I put together a little demo file for showing some various object effects. That database file also had a little gimmicky effect that had a bee flying across the screen while making a buzzing sound. The sound was generated by an invisible Web Browser Object that was created on the fly off the right side of the form. When the âKill Beeâ button is pressed the Web Browser Object is deleted, the bee disappears and the sound stops. The code that creates the Web Browser is in the .Buzzer procedure which executes the Bee.mp3 sound file that is included in the same folder. Here is that code:
object "Buzz"
deleteselectedobjects
// create formula
let theFormula={"<!DOCTYPE html>
<html lang=""en"">
<head>
</head>
<body>
<audio autoplay loop>
<source src=""file://}+unixpath(dbpath())+{/Bee.mp3"" type=""audio/mpeg"">
</audio>
</body>
</html>"}
// create web browser with autoplay sound file off window
Newformobject "WebBrowserObject",
"$WebBrowserFormulaMode","Formula",
"rectangle",rectanglesize(1, rright(info(âwindowrectangleâ))+100, 1, 1),
"name","Buzz",
"Formula",theFormula
This is a screen shot of that database showing the bee in flight:
You can also check out the various effects by clicking any of the top four buttons. The zipped folder containing the database and the sound file are here:
tFile = â/Users/username/pathToFile/File Name To Play.m4aâ
tCommand = {set soundPath to â} + tFile + {â
do shell script âafplay " & quoted form of soundPath & " > /dev/null 2>&1 &â}
applescript tCommand, tResult
Omit the " > /dev/null 2>&1 &", and Panorama will come to a dead stop, until the sound completes.
afplay is a utility included in OSX since 10.5 (look in /usr/bin), but doesnât play protected audio files. It handles most audio file types, though. A potential advantage of afplay over QuickTime is itâs process opens and closes without the user being aware.
The background for this came from Mac OS X Hints. A search for âregulusâ on that page will show the code used in these examples. A few other suggestions there may also be worth exploring.
James - Oh, much older that that. I believe it was at least in Pan3. It was one of the first example programs provided with the database. It had some bird photos - to show off flash art. And it played the bird sounds - FlashAudio - as they were brought up in the form. I always thought it was cool and could imagine other uses. But it didnât seem to generate much enthusiasm. So I was kind of joking with Jim with my post.
In Panorama 6 and earlier, the playsound statement was only usable with antiquated sound resources and only after first opening the resource with opensoundâŚ
Ericâs solution seems the easiest to implement today but does have one restriction in that it will not allow a sound to repeat (loop) until turned off. I found a hack to loop the afplay sound but there was a noticeable delay between each loop. Worse than that, I could not stop the sound from playing even with a killall afplay command in the terminal and I had to restart my computer to get rid of it. So, for the use I needed it was only the Web Browser scheme I showed previously that allowed for continuous sound play.
For Ericâs scheme you could use shellscript {killall afplay> /dev/null 2>&1 &} on a âStopâ button to turn the playing sound off when needed. You can also incorporate the afplay -v option to set the playback volume between .01 (lowest volume) and 1 (highest volume). Here is code to play my Bee.mp3 sound file in the same folder as the database at a volume of 60%:
One further note, I just had to find out what the trailing entries were used for in Ericâs shellscript. The {> /dev/null 2>&1 &} part of the shellscript is to prevent any errors from being returned and allowing the script to execute asynchronously in the background.
Today I exported the Internet Radio streams of my Mojaveâs iTunes as playlists (in order to transfer them into Catalinaâs Music.app). I noticed that those playlist exports are tab separated text files. So I made a Panorama X database out of these text files, and when this was completed, I wanted to be able to start the playback of the streams from within my database.
A little bit of research led me to the excellent site Dougâs Apple Scripts, and then it was very easy to implement a little AppleScript that plays the stream of the active record in iTunes:
applescript |||
tell application "iTunes"
open location ||| + quoted(URL) + |||
end tell
|||