Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007
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.
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>