as3 netstream double audio?
- Started
- Last post
- 10 Responses
- wwfc
hi all,
just managed to work out how to get flv's to load up dynamically using xml - it all works well apart from this one problem that i have.
when the thumbnail for the flv is clicked the preloader appears and the flv starts to load - but for some reason the audio begins to play almost immediately - then when the flv actually loads then the audio plays again whilst the initial (unwanted) audio carries on playing!
this is the script for the netstream:
private function onInitialize():void
{
_connection = new NetConnection();
_connection.addEventListener(Net... onConnectionNetStatus, false, 0, true);
_connection.addEventListener(Sec... onConnectionError, false, 0, true);
_connection.addEventListener(Asy... onConnectionError, false, 0, true);
_connection.addEventListener(IOE... onConnectionError, false, 0, true);
_connection.objectEncoding = ObjectEncoding.DEFAULT;
_connection.client = {
onBWDone: onBWDone
};//_connection.connect("rtmp://yo...
_connection.connect(null);
}private function onConnectionError(...args):void
{
trace("Test.onConnectionError...
}private function onConnectionNetStatus(event:NetS...
{trace("**** code **** " + event.info.code);
switch (event.info.code)
{
case "NetConnection.Connect.Success":
_stream = new NetStream(_connection);
_stream.client = {
onMetaData: onMetaData,
onCuePoint: onCuePoint
};_video = new Video();
_video.smoothing = true;
addChild(_video);_video.attachNetStream(_stream);
var xscaler:Number = (1 / _video.width) * stage.stageWidth;
var yscaler:Number = (1 / _video.height) * stage.stageHeight;
_video.scaleX = xscaler;
_video.scaleY = yscaler;
_stream.play(videoPath + imageArray[largeImageItem].large... 0);i really don't understand why it plays double???
Anyone had this problem before?
- rounce0
You've handling the video object in the wrong order from the looks of things:
Instantiate -> attachNetStream() -> play() -> addChild()
..is what I've always known to work.
- wwfc0
...okay cheers rounce i'll have a look at that - i have feeling i changed it to that earlier - i'll see what gives though ;-)
- wwfc0
...still no joy - it still plays audio whilst the video is loading and doubles up the audio!
audio always starts at the same point of loading - no one ever dealt with this before?
- wwfc0
...would this be anything to with it? the flvs are all loaded via xml - should i be doing this differently?
private function onUpdateTimer(event:TimerEvent...
{
trace("Test.onUpdateTimer()");
trace("\t"+_stream.bytesLoaded+" of "+_stream.bytesTotal+" bytes loaded.");
trace("\t"+_stream.time+" of "+_metaData.duration+" played.");
trace("\t_stream.bufferLength...if (_stream.time >= _metaData.duration)
{
_updateTimer.removeEventListener... onUpdateTimer);
_updateTimer = null;
}
}
- maximillion_0
i would separate the audio into a separate object so that you can control it much better. Listen for the events broadcast from the stream and tie these into the audio control.
- wwfc0
that sounds reasonable but the problem is the flv's will ultimately be uploaded by the client - uploading flv files and updating xml is pushed to the limit as it is - and that is simply for thumb/flv/title/description
is there no way of telling the audio to wait until it is all loaded and then play it 'all'
...hmmm - i wonder about setting it to pause at start and then the user clicks to play? - anyone know if this is a good idea or how easy to impliment it is?
- maximillion_0
when I separate I mean do it with yr AS not separate audio files. I will try and dig out and example for you
- wwfc0
...aah! okay - yes, that might be an idea indeed!
yes, please dig away :-)
nice one!
- wwfc0
...ooh! looks good - thanks man ;-)