The following EMBED tag will play a midi or wav file as soon as it's loaded:
The following allows you to control when the midi or wav file plays:
Creating a play list
The item variable keeps a count of how many tunes there are and the total variable holds the total number of seconds for the all the tunes; i.e., the time/length of the play list.
The setTune() function is used to add each Tune object to the myTune object array.
Displaying the midi hifi
The remainder of the form -- i.e., the play, stop and start buttons, along with the Single Play, Cycle Play and Random Play play options, as well as the Time Played, Time Remaining, Track Time and Total Time time options and seconds digital clock -- are all output using HTML.
The totaltime variable is set to the value returned by the formatTime() function, which is passed as its argument the value of total, i.e., the total time of the Play List in seconds.
When the tunes select array is changed, the selects onChange event handler invokes the hifi() function only if playing passing as its argument the selectedIndex of the tuner forms tunes select array.
When the document has fully loaded, the BODY tags onLoad event handler invokes the resetstartTime() and updateStatus() functions.
When the play ('>') button is pressed, the buttons onClick event handler invokes the hifiStart() function, passing as its argument the selectedIndex of the tuner forms tunes select array. When the stop ('#') button is pressed, the buttons onClick event handler invokes the hifiStop() function. When the pause ('||') button is pressed, the buttons onClick event handler invokes the hifiPause() function. When the time select array is changed, the selects onChange event handler invokes the updateStatus() function.
Controlling the midi hifi
The hifiStart() function receives the number (no) of the selected tune. It first updates the value of the global variable random with the selected property of the last entry within the play select array. If random play has been selected, then a pseudo-random number (rnd) is generated within the range of the number of item tunes. This is then compared against the current tunePlaying; if it's the same, then the rnd number is increased by 1. The hifiPlay() function is invoked either with the rnd or no number.