Sound question: notification at end of play

Rudi Angela olmeca at netscape.net
Sat Mar 9 12:29:53 UTC 2002


"Lex Spoon" <lex at cc.gatech.edu> wrote:

>olmeca at netscape.net (Rudi Angela) wrote:
>> Hi there,
>> Is there a way I can have my object notified when a sound has finished playing?
>> I'm playing mp3 files as part of a presentation. When the  playing is done the presentation should continue to the next 'slide'.
>> I've tried adding making my object dependent on the sound and sending a changed: message to the sound in SoundPlayer playLoop, but it doesn't work.
>> Any ideas, suggestions?
>
>
>The easiest thing would be to check in a #step method.

Thanks for the tip, Lex, you're right. The general solution appears to be placing a call to 'changed: #donePlaying' in the step (or analogous) method of the media player object, wrapped inside a check for 'end of media'.
In the specific case of the StreamingMP3Sound, the stepping method is 'playSampleCount: n into:aSoundBuffer startingAt: startIndex'.
Here I added the 'changed:' call:
.....
(totalSamples - current) < n ifTrue: [ '"at the end"
self repeat ifTrue: [ ... loop ...] ifFalse:[self changed: #donePlaying].
.....

In the case of the Flash player the stepping method is the 'stepForward' method in FlashSpriteMorph:
.....
self loopFrames ifTrue: [... loop ...]
ifFalse: [ self changed: #donePlaying].

This appears to work flawlessly, as long as I do a garbageCollect afterwards. I'm using a 'MultiMediaPlayer' object to load Flash animations and sound tracks and then play all in synch. When all the tracks are done playing, the sounds and animations are disposed of and the next 'multimedia slide' is loaded and played.
Even given the fact that some of the work is done in separate threads the 'changed:' notification appears to work allright (as long as I call garbageCollect between slides).
>
>You can do this with the etoy system, by the way.  EToys is fabulous for
>presentations.  

Yes, I'm quite charmed by EToys myself. In a possible follow-up of my current Squeak project I will be making many example etoys. I'm really looking forward to that.

>You can make a script watch the progress bar of an
>MPEGPlayer, and then do something when the progress bar reaches its
>maximum.  I believe MPEGPlayer can be made to work with other sounds,
>too.
>
>I've posted an example as ChangeOnSoundEnd on Bob's SuperSwiki.  

Thanks for this compelling illustration of your idea! Where would we be without SuperSwiki's!
There are reasons why I can't use EToys everywhere in this project, though.

Rudi Angela
-- 




__________________________________________________________________
Your favorite stores, helpful shopping tools and great gift ideas. Experience the convenience of buying online with Shop at Netscape! http://shopnow.netscape.com/

Get your own FREE, personal Netscape Mail account today at http://webmail.netscape.com/




More information about the Squeak-dev mailing list