Standalone application problem
Dan Soneson
sonesond1 at southernct.edu
Thu Apr 19 13:56:35 EDT 2007
Hi Andrew,
I treat external audio, video and even images much the same way as I
would
in a web site. When putting together a standalone that references
this media
I put the media in a separate folder within the folder that houses
the standalone
and work with a relative link to the media. Say your standalone is
in a folder
called "My Standalone." Create a media folder within that folder and
place your
media in this new folder (or copy your media folder into this new
standalone
folder). Then you query the path of the standalone, replace the
standalone name
in the path with the media folder name, and reference your images/
audio/video
files using this new path:
put the fileName of this stack into theStackPath
set the itemDelimiter to "/"
put "MyMedia" into item -1 of theStackPath
Now you have a reference point for all your media, as long as it is
housed in the
"MyMedia" folder. You can retain this in several ways. Perhaps the
easiest is to
set a custom property of either the stack or the card:
set the uMediaFolder of this stack to theStackPath
Probably the best place to do this is in the preOpenStack handler, on
the card script
of the first card to open when the stack opens. Don't put it in the
stack script, or this
script will execute any time a stack opens within your standalone. So
the preOpenStack
handler on the first card of your stack would look like this:
on preOpenStack
put the fileName of this stack into theStackPath
set the itemDelimiter to "/"
put "MyMedia" into item -1 of theStackPath
set the uMediaFolder of this stack to theStackPath
end preOpenStack
Any time you want to set the filename of a player now, you call up
the uMediaFolder
of the stack and put the name of the media file after this. Then you
set the filename
of the player to this path:
put the uMediaFolder of this stack into theFolderPath
put theFolderPath & "sound_01.aif" into theNewFile
set the filename of player 1 to theNewFile
You can place the above lines into a preOpenCard handler in the card
script of the
card that contains the player, or you can place it on a mouseUp
handler to set the new
filename.
This works nicely if you have only one audio file to play. If you
want to play several, or
want to call up a specific audio file to play, you can use the
uFolderPath of the stack to
get a list of the files in the media folder, display them as a list
in a list field. In the script
of the list field you can write a mouseUp handler to set the filename
of the player to the audio
file that you click on.
In a button or preOpenCard handler you can put a script like this:
on preOpenCard -- goes in the card script
put the uMediaFolder of this stack into theFolderPath
put the defaultFolder into theOrigDefault -- keep track of the
original default folder
set the defaultFolder to theFolderPath -- allows us to get a
listing of all the media files in this folder
put the files into theMediaFiles -- this gets a list of all files
in the default folder, one file per line
-- you may want to do some filtering of this list here, i.e.
include only files with ".wav" extension etc.
filter theMediaFiles with "*.wav" -- this is optional, if you have
a mixed type of files
put theMediaFiles into fld "audio files" -- this is the scrolling
list field, you can name it what you want
set the defaultFolder to theOrigDefault -- restore the original
default folder
end preOpenCard
Then in your list field script you would have a handler like so:
on mouseUp
put the selectedText into theFile
set the filename of player 1 to the uMediaFolder of this stack &
"/" & theFile
end mouseUp
The point is, that if you set up a connection to the media folder
when you first open your stack, either
within the development environment or as a standalone, you can call
up any individual file pretty
easily.
It was nice to meet you at the ISLS conference in Hawaii, and I'm
delighted you are checking into
Revolution. Welcome to the Revolution!
Dan
More information about the use-livecode
mailing list