sample #20
inserting mp3 sound event
  1. <?php
  2. include("sample_utils.php"); // provides some utils and using mk
  3.  
  4. $sndFN = "creak_closing.mp3";
  5. $swfFN = "soundStart.swf";
  6. $flasmFN = "f6_sound_preload.flm"; // flasm syntax file from where we'll inject mk assembled bytecode
  7.  
  8. $snd = new MKsound_container("", $sndFN); // start a fresh sound data with soundID = 1 by default
  9. $sndAssetTD = $snd->set_linkage_name("creak"); // we'll use as linkage sound
  10. $sndTD = $snd->update_tagData(); // tag data
  11. $sndSSHTD = $snd->update_soundStreamHead(); // streaming sound settings
  12.  
  13. $as = new MKActionScript_container(); // actionscript container VERY EXPERIMENTAL
  14. $frameTD1 = $as->assemble_from_file($flasmFN, 1); // compile frame #1 (0), contain a simple blind preload
  15. $frameTD2 = $as->assemble_from_file($flasmFN, 2); // compile frame #2 (1), attach sound and play
  16.  
  17. $swf = new MKswf($swfFN); // a fresh new swf
  18. $swf->set_swfDir(SERVER_MKTMP); // we'll store in tmp
  19. $swf->add_tagData($sndTD); // start to populate, sound
  20. $swf->add_tagData($sndSSHTD); // ... streaming settings
  21. $swf->add_tagData($sndAssetTD); // ... sound linkage
  22. $swf->add_tagData($frameTD1); // ... actionscript for frame #1
  23. $swf->add_tagData($frameTD2, 2); // ... actionscript form frame #2
  24.  
  25. $swf->swf_output(); // save
  26.  
  27. $swfHeader = $swf->fetch_assoc(); // prepare to publish to the browser
  28.  
  29. $str = render_swf_box($swfHeader, $imgDir, false);
  30. $str .= "<br/><strong>" .$swfFN ." created in :<br />" .SERVER_MKTMP ."</strong>";
  31. echo show_content($str, basename(__FILE__));
  32. ?>

mp3 sound can be handled by mk to insert in swf files. It reads its properties to store the needed info for player and sound data. I use audacity for testing and ID3 "compatibile" (v1) header. I've noticed some quirks using v2 header so it is suggested to avoid those idtag.

For preloading issue you see a reference to MKflasm assembler, even in very experimental stage it compile without problem the given flasm syntax file. The bytecode is used to preload movie, wait for availability of sound and play it.
Note that sound was inserted as linkage, then used by bytecode. In the next samples we will see a sound event applied to button.
mikrokosmos