Mpeg Player Code

Javascript code for an mpeg player


function newMpegPlayer(cls, scr, width, height, volume, controller, autoplay, loop)
   // cls = CSS:object.class for newMpegPlayer
   // scr = source mpeg (.mp3)
{
   var playerCode = '';
   playerCode += '<object ';
   playerCode += 'classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" ';
   playerCode += 'codebase="http://www.apple.com/qtactivex/qtplugin.cab" ';
   playerCode += 'class="' + cls + '" ';
   playerCode += 'width=' + width + ' height=' + height + '>';
   playerCode += '<param name=src value="' + scr + '">';
   playerCode += '<param name=volume value=' + volume + '>';
   playerCode += '<param name=controller value=' + controller + '>';
   playerCode += '<param name=autoplay value=' + autoplay + '>';
   playerCode += '<param name=loop value=' + loop + '>';
   playerCode += '<embed ';
   playerCode += 'src="' + scr + '" ';
   playerCode += 'type="audio/mpeg" ';
   playerCode += 'width=' + width + ' height=' + height + ' ';
   playerCode += 'volume=' + volume + ' ';
   playerCode += 'controller="' + controller + '" ';
   playerCode += 'autostart="' + autoplay + '" ';
   playerCode += 'loop="' + loop + '" ';
   playerCode += 'pluginspace="http://www.apple.com/quicktime/download/">';
   playerCode += '</embed>';
   playerCode += '</object>';
   
   document.write(playerCode);
}
This javascript function is based on HTML code from

   http://developer.apple.com/safari/library/documentation/
      QuickTime/Conceptual/QTScripting_HTML/
      QTScripting_HTML_Document/chapter_1000_section_3.html

Examples of use

In the head:

<style type="text/css">
   object.player {
      margin-left: 6.0ex;
      padding: 2.0ex;
      background-color: yellow;
      border-color: black;
      border-style: double;
   }
</style>
In the body:

<script type="text/javascript">
   newMpegPlayer("", "LouieLouie_Berry.mp3",
      180, 16, 75, "true", "false", "false");
</script>


or again, using the “player” style above,

<script type="text/javascript">
   newMpegPlayer("player", "LouieLouie_Berry.mp3",
      180, 16, 75, "true", "false", "false");
</script>





[home]
Last updated: 2-May-09
Valid HTML 4.01 Transitional Valid CSS!