Skip to main content
Known Participant
October 1, 2008
Question

streaming audio in AS3/CS3

  • October 1, 2008
  • 9 replies
  • 693 views
I've been working on an audio streaming application for the last couple days. My current progress can be viewed at figmentmedia.ca/test.html. I've got a problem with this release. Look at the tan coloured line, near the base of the window, to the right of the control buttons (of which only play and pause work). That line is supposed to be a loading bar. As you will probably notice it does not work. The code I've attached is located in the first frame of my movie. The second last line there, "mc_loaded.width = 297/(soundClip.bytesLoaded/soundClip.bytesTotal);", is the one giving me the trouble. After troubleshooting many different options.. none of which worked, I believe.. what is loading may be the variable. Regardless of what progress the bar is showing, it's not showing the progress of the sound clip. Any help would be greatly appreciated.

Thanks in advance, Calvin Tennant.
This topic has been closed for replies.

9 replies

Known Participant
November 28, 2008
Known Participant
October 1, 2008
Crashed your browser? Really? What happened before the browser shut down... did it try to play what it hadn't loaded? My internet is pretty speedy so I couldn't test that. I'll have a look at that link. Thanks for all the help, I'm a designer who got too comfortable with as2. I love what as3 can do, but I'm a little slow on the uptake I think. Feel free to stay in touch eh, my email/contact info is on figmentmedia.ca. Have a good one :)
Known Participant
October 1, 2008
And it worked perfectly. Brilliant. Last time, figmentmedia.ca/test.html. Thanks so much! The final code is down here for anyone interested. Let me know what you use it for, otherwise its yours. The code goes on the first frame of the movie and you'll need a movie clip with the instance name "mc_control", containing "btn_play" on top of "btn_stop". Again thank you so much Colin.
Colin Holgate
Inspiring
October 1, 2008
It's quite an interesting effect! Other than it crashed my browser, resetting my preferences too.

Read this page:

http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000291.html

There's a routine shown in there that will give you an estimated length for the sound. That should help make the play head less twitchy.


Known Participant
October 1, 2008
:D Thank you so much Colin.
I changed:
soundClip.addEventListener(Event.COMPLETE, onComplete);
to
soundClip.addEventListener(Event.ACTIVATE, onComplete);

Now that I am able to see the movie play, before it is fully loaded, I see that "soundClip.length" is referring to the length of the clip that has been loaded, rather than the entire sound clip. When you watch the movie as the song loads you see the vertical bar float back and fourth across the horizontal bar. Is there a way to measure the length of the entire sound clip, rather than just the amount that has already been loaded? Again the URL is figmentmedia.ca/test.html. You may have to clear your cache. Thanks so much.

Calvin Tennant
Colin Holgate
Inspiring
October 1, 2008
You're not setting your listeners until the sound is completely loaded:

function onComplete(event:Event):void{
mc_control.btn_play.addEventListener(MouseEvent.CLICK, playSound);
mc_control.btn_stop.addEventListener(MouseEvent.CLICK, stopSound);
}
Known Participant
October 1, 2008
Duh! Okay, that was a lot easier than I thought it would be, thank you so much Colin! I do have another problem however, now that I can see the load progress (again, figmentmedia.ca/test.html), it is supposed to start playing after eight seconds. I found a snippet of code on the adobe website that gave me this line: "var soundContext:SoundLoaderContext = new SoundLoaderContext(8000, true);". From the example on my website, you can see that it wont play, until it is fully loaded. Any idea why not?
Colin Holgate
Inspiring
October 1, 2008
There are two lines in his enter frame function, one for play progress, one for loading progress. At least it would be if he multiplied instead of dividing.


kglad
Community Expert
Community Expert
October 1, 2008
your code doesn't match your description.

from your description, it appears you want to display the load-progress of test1.mp3.

from your code, it appears you want to display the play-progress of test1.mp3.
Colin Holgate
Inspiring
October 1, 2008
This:

mc_loaded.width = 297/(soundClip.bytesLoaded/soundClip.bytesTotal);

should be:

mc_loaded.width = 297*(soundClip.bytesLoaded/soundClip.bytesTotal);