How to create Flash movie playing streaming MP3 audio (playing on-the-fly)

Submitted by eLenka on 19 April, 2011 - 15:36

Playing streaming MP3 music in flash movie generated with SWF Scout library

SWF Scout provides ability to use built-in ActionScript compiler (requires ASC or Expert Edition).

To create a flash movie with streaming audio we will create a simple flash movie and will place an actionscript code that will initialize Sound object and will load and play flowers.mp3 file as streaming audio.

ActionScript code is:

var mysound:Sound = new Sound();
mysound.loadSound('http://delphiflash.com/download/flowers.mp3', true);

the second parameter in loadSound() function is IsStreaming. We set it to TRUE to load flowers.mp3 as streaming audio.

flowers.mp3 is almost 600KB but flash player will start to play it after few seconds after initial buffering and will download mp3 while playing. You should already hear the music.  

Important note: mp3 audio filename is case-sensitive!

To compile this code just pass it to SCRIPT_Compile function and SWF Scout will compile actionscript code using internal ActionScript compiler. Please note that to use ActionScript compiler in registered version of SWF Scout SDK you should purchase ASC or Expert Edition.

VBScript Source Code:

  W = 640
  H = 480
  Set Movie = CreateObject("SWFScout.FlashMovie")
  Movie.InitLibrary "demo","demo"
 
  Movie.BeginMovie 0,0,W,H,1,12,6
  Movie.Compressed = true
  Movie.SetBackgroundColor 255,255,255
 
 Font = Movie.AddFont( "Arial",12,true,false,false,false,0)
 FontBig = Movie.AddFont("Arial",40,true,false,false,false,0)
 
 Text = Movie.AddText("Playing streaming sound(using ActionScript) from:",0,0,0,255,Font, 0, 80, 170, 160)
 Movie.PlaceText Text,Movie.CurrentMaxDepth ' place text
 Text = Movie.AddText("http://delphiflash.com/download/flowers.mp3",0,0,0,255,Font, 0, 110, 170, 320)
 Movie.PlaceText Text,Movie.CurrentMaxDepth ' place text

Script = Movie.AddScript
 
Movie.SCRIPT_Compile "var mysound:Sound = new Sound(); mysound.loadSound('http://delphiflash.com/download/flowers.mp3', true);"
' Second parameter in mysound.LoadSound is IsStreaming. We set it to TRUE

Movie.ShowFrame 1
 
Movie.EndMovie
 
Movie.SaveToFile "swfscout_StreamingSound.swf"

 

Download source code: