View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

Reload fun

Using the reload tag

Determining the length of Midi/MPG's is surprisingly simple in Squeak.

s _ MIDIFileReader scoreFromFileNamed: afile.
^(1.0 x s durationInTicks) / (2.0 x s ticksPerQuarterNote).

Here afile is of course, a path to a midi, and s is just a holder for its score.

This little snippet of code should be fairly self explanatory. One issue is that it does overestimate the length of the song a bit, so you may wish to adjust the static values more to your liking.

You might want to have a look at the MIDIFileReader and ScorePlayer
classes for more about this. In particular, the tempoOrRateChanged method in ScorePlayer might be of use.


s _ ScorePlayer onScore: (MIDIFileReader scoreFromFileNamed: afile).
s jumpToTick: 0.
^((60.0 / (s tempo x s rate x s score ticksPerQuarterNote)) x (s durationInTicks)).

This should be a little bit better for you.

foo _ MPEGPlayer playFile: 'c:\music\Cowgirl.mp3'.
foo seekToHere: 1.0 forStream: 0.
foo setupStream: 0.
foo createSoundFrom: 0.
foo getTimeCode.

This will make a new instance of MPEGPlayer ( foo ), and getTimeCode returns the length of the mpeg in seconds.

Embedding Sound Files in HTML

You can use the OBJECT tag to instruct a browser to download and play the soundfile at a specified URL. The syntax typically looks like this:
<OBJECT data="http://...." type="audio/aiff" autostart=true></object>

Causing the Reload

Once you know the length of the song you want to serve up to the good people, the rest is a walk in the park. Remember how to use the refresh tag? no? well then pull out your 1501/1311 lab manuals, or, barring that, go find an example on the web somewhere.

meta http-equiv="Refresh" content="5; url=1251"

That should give something to work with.

Now that you know how to refresh, you know how to embed squeak into html, and you know to use the PWS, you should be all set. (You have been going to lecture, and reading the examples in the book, haven't you?).


Links to this Page