Terminating an audioclip

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

jmk_phd
Posts: 216
Joined: Sat Apr 15, 2017 8:29 pm

Terminating an audioclip

Post by jmk_phd » Wed Oct 02, 2019 2:01 am

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

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10320
Joined: Wed May 06, 2009 2:28 pm

Re: Terminating an audioclip

Post by dunbarx » Wed Oct 02, 2019 2:41 am

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

Klaus
Posts: 14194
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Terminating an audioclip

Post by Klaus » Wed Oct 02, 2019 10:16 am

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

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10320
Joined: Wed May 06, 2009 2:28 pm

Re: Terminating an audioclip

Post by dunbarx » Wed Oct 02, 2019 2:45 pm

Klaus.

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

Craig

Klaus
Posts: 14194
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Terminating an audioclip

Post by Klaus » Wed Oct 02, 2019 2:46 pm

What does the error say?

Klaus
Posts: 14194
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Terminating an audioclip

Post by Klaus » Wed Oct 02, 2019 4:35 pm

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

jmk_phd
Posts: 216
Joined: Sat Apr 15, 2017 8:29 pm

Re: Terminating an audioclip

Post by jmk_phd » Wed Oct 02, 2019 5:23 pm

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

Klaus
Posts: 14194
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Terminating an audioclip

Post by Klaus » Wed Oct 02, 2019 5:49 pm

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
...

jmk_phd
Posts: 216
Joined: Sat Apr 15, 2017 8:29 pm

Re: Terminating an audioclip

Post by jmk_phd » Thu Oct 03, 2019 12:33 am

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

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: Terminating an audioclip

Post by bogs » Thu Oct 03, 2019 9:51 am

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
Image

Klaus
Posts: 14194
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Terminating an audioclip

Post by Klaus » Thu Oct 03, 2019 10:10 am

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

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: Terminating an audioclip

Post by bogs » Thu Oct 03, 2019 10:32 am

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!
Image

Klaus
Posts: 14194
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Terminating an audioclip

Post by Klaus » Thu Oct 03, 2019 10:41 am

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.

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: Terminating an audioclip

Post by bogs » Thu Oct 03, 2019 10:46 am

AAAwwwwwwwwwwwwwwwwwwwwwwww SHUCKY DARNS! :evil:
Image

Klaus
Posts: 14194
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Terminating an audioclip

Post by Klaus » Thu Oct 03, 2019 11:10 am

Well except that button in the toolbar everything else should be identical in version 2.1 and 2.2. 8)

Post Reply