Page 1 of 2

Terminating an audioclip

Posted: Wed Oct 02, 2019 2:01 am
by jmk_phd
I'm sure that I'm missing something really simple:

When my psychological test opens to a new card/item, it plays an audiofile that "speaks" the text displayed on screen.

Originally, I'd required the audiofile to play until done before the user registered a response, via either button or keyboard press. This worked just fine. But -- in order to speed up the test -- my client wants to terminate the audio as soon as a response is entered.

I save the full path to the audiofile in a mainstack custom property (cCurrentAudioFilePath) -- so I can identify whether the audio needs to be terminated prematurely when moving to the next item. When so, I've employed the following routine:

Code: Select all

   -- NEW: TERMINATE AUDIOFILE AS SOON AS RESPONSE IS GIVEN
   local tThisAudioFile
   put the cCurrentAudioFilePath of stack "EAS_SABE" into tThisAudioFile
   stop playing audioClip tThisAudioFile
This results in an error, but I'm not sure why.

Any help will be appreciated.

jeff k

Re: Terminating an audioclip

Posted: Wed Oct 02, 2019 2:41 am
by dunbarx
Hi.

Syntax looks good. Are we sure that you have described the clip accurately?

What is the error?

On another note, there is nothing wrong with being verbose, as long as you know the three lines you posted can be one line if you want.

Craig

Re: Terminating an audioclip

Posted: Wed Oct 02, 2019 10:16 am
by Klaus
Hi Jeff,

if you started the clip with -> play audiclip "path/to/clip"
then you just need:

Code: Select all

...
play stop
...
This is in the dictionary, which is WAY better than its reputation (nudge, nudge 8) )!

Since with PLAY we can only play one audio/video at a time, there is no need
to also supply the name or path to the clip here.


Best

Klaus

Re: Terminating an audioclip

Posted: Wed Oct 02, 2019 2:45 pm
by dunbarx
Klaus.

Well and good, if that is a simplification. But we still have an error.

Craig

Re: Terminating an audioclip

Posted: Wed Oct 02, 2019 2:46 pm
by Klaus
What does the error say?

Re: Terminating an audioclip

Posted: Wed Oct 02, 2019 4:35 pm
by Klaus
Just made a quick test and everything worked as advertized!

Code: Select all

on mouseUp
   play ac "/Users/klaus2/Desktop/davey.aif"
end mouseUp

Code: Select all

on mouseUp
   play stop
end mouseUp
No error, the sound just stops as exspected.

LC 9.5.0 on macOS 10.14.6

Re: Terminating an audioclip

Posted: Wed Oct 02, 2019 5:23 pm
by jmk_phd
Craig and Klaus --

The example from the Dictionary entry for "stop" that I'd followed, namely,

Code: Select all

stop playing audioClip "track1"
(of course, substituting the actual file path) resulted in an "object not found" error (even though the referenced path to the audiofile -- the same as used first to trigger the "play" command -- was valid).

However, the simpler and more elegant alternative suggested by Klaus (and indeed buried in the Dictionary "play" entry)

Code: Select all

play stop
does seem to work without a glitch. Makes sense because only one audiofile plays at a time.

Thanks much to you both for the help!

jeff k

Re: Terminating an audioclip

Posted: Wed Oct 02, 2019 5:49 pm
by Klaus
If you happen to also play a videoclip at the same time as the audioclip (no idea if this is possible) you can define WHAT to stop:

Code: Select all

...
## Stop an audioClip
play stop ac
...
## Stop a videoclip
play stop vc
...

Re: Terminating an audioclip

Posted: Thu Oct 03, 2019 12:33 am
by jmk_phd
Klaus --

Just out of curiosity, where are the abbreviations "ac" and "vc" (for "audioclip" and "videoclip" respectively) documented? Never saw these in the LC 8.10 Dictionary, although I may well be wrong.

(BTW, I'm still using Indy LC 8.10 on an everyday basis because support for macOS 10.6.8 was dropped with LC 9.x. When switching to a startup volume that boots a newer macOS (Sierra), LC 9.x throws errors for innocuous loops that worked just fine in my 8.10 code. I know that I'll have to deal with this eventually, but fixing problems such as the one you'd just solved for me has been my first priority.)

jeff k

Re: Terminating an audioclip

Posted: Thu Oct 03, 2019 9:51 am
by bogs
jmk_phd wrote:
Thu Oct 03, 2019 12:33 am
Just out of curiosity, where are the abbreviations "ac" and "vc" (for "audioclip" and "videoclip" respectively) documented? Never saw these in the LC 8.10 Dictionary, although I may well be wrong.
I may be speaking out of turn as Klaus hasn't answered yet, but I don't think you will find those in the dictionary, Jeff, I suspect that those abbreviations refer to either:
...your file name for the one your using or...
...the player name, number, or ID (player "myPlay", player 2, player id 20725)

Just a guess on my part :D

Re: Terminating an audioclip

Posted: Thu Oct 03, 2019 10:10 am
by Klaus
Hi Jeff,

as Bogs stated, these abbreviations are not documented and I cannot say where I learned
them in the last twenty years working with LC and its ancestors.

But they only refer to an audio- or videoclip that might be currently playing.
That is an heritage from the old Metacard days where we did not have player objects and could only play
one clip at a time. Therefore no special differentiation by name or filename was neccessary.

Here a maybe incomplete list of possible abbreviations that I alway use:
cd = card
btn = button
fld = field
grp = group
sb = scrollbar
img = image
grc = graphic


Best

Klaus

Re: Terminating an audioclip

Posted: Thu Oct 03, 2019 10:32 am
by bogs
Klaus wrote:
Thu Oct 03, 2019 10:10 am
That is an heritage from the old Metacard days where we did not have player objects
I'd love to know when that was! The oldest version of Mc I could find, 2.2 (powered by the Mc 2.5 engine :twisted: ) had a player object:
MetaCard2-2PlayerObject.png
Dis must be da play(erObject)...
If you still have the stacks for the IDE hanging around from a time before that, I'd sure appreciate seeing them!

Re: Terminating an audioclip

Posted: Thu Oct 03, 2019 10:41 am
by Klaus
I started with Metacard in 1999 when the first Mac and Win version appeared.
At that time it was already version 2.1, and they added the QuickTIme player object a little later.
But I'm afraid I don't have any MC file without the player in the toolbar.

Re: Terminating an audioclip

Posted: Thu Oct 03, 2019 10:46 am
by bogs
AAAwwwwwwwwwwwwwwwwwwwwwwww SHUCKY DARNS! :evil:

Re: Terminating an audioclip

Posted: Thu Oct 03, 2019 11:10 am
by Klaus
Well except that button in the toolbar everything else should be identical in version 2.1 and 2.2. 8)