Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 03-31-2006, 03:19 AM   #1
marcusw02
Registered User
 
Join Date: May 2004
Location: Australia
Posts: 30
Default Video paused when loading via NetStream object

Hi,

I'm having a problem loading an FLV file via the NetStream object.

The following is on frame 1 of my root timeline:
Code:
loadMovieClip();

function loadMovieClip():Void {
	// Create new NetConnection object
	var netConn:NetConnection = new NetConnection();
	netConn.connect(null);
	// Create new streaming object and attach the NetConnection object
	var netstream:NetStream = new NetStream(netConn);
	
	_root.bgVideo.attachVideo(netstream);
	netstream.setBufferTime(5);
	netstream.play("champcrash.flv");
	
	netstream.onStatus = function(infoObject:Object) {
		trace("NetStream.onStatus called: ("+getTimer()+" ms)");
		for (var prop in infoObject) {
			trace("\t"+prop+":\t"+infoObject[prop]);
		}
		trace("Loaded: " + this.bytesLoaded);
		trace("bytesTotal: " + this.bytesTotal);
		trace("");
	};
};
Nothing too complicated there... its just loading 'champcrash.flv' into the 'bgVideo' object on the stage. My problem is that with the code as above, the video is paused on the first frame, and doesn't progress.

The odd thing is, if I take the contents of the 'loadMovieClip' function, and just place it on the same frame, without any function or function call, then the video will play correctly, without pausing. Code looks like:

Code:
	// Create new NetConnection object
	var netConn:NetConnection = new NetConnection();
	netConn.connect(null);
	// Create new streaming object and attach the NetConnection object
	var netstream:NetStream = new NetStream(netConn);
	
	_root.bgVideo.attachVideo(netstream);
	netstream.setBufferTime(5);
	netstream.play("champcrash.flv");
	
	netstream.onStatus = function(infoObject:Object) {
		trace("NetStream.onStatus called: ("+getTimer()+" ms)");
		for (var prop in infoObject) {
			trace("\t"+prop+":\t"+infoObject[prop]);
		}
		trace("Loaded: " + this.bytesLoaded);
		trace("bytesTotal: " + this.bytesTotal);
		trace("");
	};
The code is EXACTLY the same, except it isn't within a function, yet the latter example plays the video correctly, and the first example doesn't.

This is driving me crazy... any suggestions??

thanks,
Marcus.
marcusw02 is offline   Reply With Quote
Old 03-31-2006, 03:52 AM   #2
mlecho
Registered User
 
Join Date: Oct 2005
Posts: 23
Default

i have encountered this a few times myself. I am not the man to explain the why's (technically) but my understanding is that flash can not load AND play the video, netConnection, and stream fast enough in the blink of a called funciton. However, can you try using all the code except the play, outside of the function?

Code:
// Create new NetConnection object
	var netConn:NetConnection = new NetConnection();
	netConn.connect(null);
	// Create new streaming object and attach the NetConnection object
	var netstream:NetStream = new NetStream(netConn);
	
	_root.bgVideo.attachVideo(netstream);
	netstream.setBufferTime(5);

function loadMovieClip():Void {
	
	netstream.play("champcrash.flv");
	
	netstream.onStatus = function(infoObject:Object) {
		trace("NetStream.onStatus called: ("+getTimer()+" ms)");
		for (var prop in infoObject) {
			trace("\t"+prop+":\t"+infoObject[prop]);
		}
		trace("Loaded: " + this.bytesLoaded);
		trace("bytesTotal: " + this.bytesTotal);
		trace("");
	};
};

loadMovieClip();
finally, just a personal thing i don't know if it makes a difference (anyone?), but i like to call the funciton after the description.

let us know if this helped, or was wishful thinking, as i did not test it.
mlecho is offline   Reply With Quote
Old 03-31-2006, 10:04 PM   #3
marcusw02
Registered User
 
Join Date: May 2004
Location: Australia
Posts: 30
Default

Thanks for the tip.

This doesn't really solve my problem though, as I need to use this code in a method in a Class, and when I do so, it behaves in the same manner as if it were in a function on the main timeline - video paused.

The code you posted worked, but I need to be able to include the initialisation code in a function also. I tried putting it in a separate function, as below, but the video was paused again:

Code:
function loadMovieClip(netstream:NetStream):Void {	
	netstream.play("champcrash.flv");
	
	netstream.onStatus = function(infoObject:Object) {
		trace("NetStream.onStatus called: ("+getTimer()+" ms)");
		for (var prop in infoObject) {
			trace("\t"+prop+":\t"+infoObject[prop]);
		}
		trace("Loaded: " + this.bytesLoaded);
		trace("bytesTotal: " + this.bytesTotal);
		trace("");
	};
};

function prepClip():Void {
	var netConn:NetConnection = new NetConnection();
	netConn.connect(null);
	// Create new streaming object and attach the NetConnection object
	var netstream:NetStream = new NetStream(netConn);
	
	_root.bgVideo.attachVideo(netstream);
	netstream.setBufferTime(5);

	loadMovieClip(netstream);
}

prepClip();
So, although I have trimmed my examples down for ease of explanation, I ultimately need to include this stuff in a class method - which is producing the same results as the above examples.

thanks in advance,
Marcus.
marcusw02 is offline   Reply With Quote
Old 04-02-2006, 06:31 AM   #4
marcusw02
Registered User
 
Join Date: May 2004
Location: Australia
Posts: 30
Default

Does anyone have another suggestion for this?? Surely there has to be a way to use this code in a class function with it all working?

thanks
Marcus.
marcusw02 is offline   Reply With Quote
Old 04-02-2006, 12:05 PM   #5
marcusw02
Registered User
 
Join Date: May 2004
Location: Australia
Posts: 30
Default

For anyone interested, here's what i've found... If I initialise the NetConnection object outside of the function, then it works. Not exactly sure why, but I'm not going to complain

thanks for the help.

Code:
var netConn:NetConnection;

function loadMovieClip():Void {
	// Create new NetConnection object
	netConn = new NetConnection();
	netConn.connect(null);
	// Create new streaming object and attach the NetConnection object
	var netstream:NetStream = new NetStream(netConn);
	
	_root.bgVideo.attachVideo(netstream);
	netstream.setBufferTime(5);
	netstream.play("champcrash.flv");
	
	netstream.onStatus = function(infoObject:Object) {
		trace("NetStream.onStatus called: ("+getTimer()+" ms)");
		for (var prop in infoObject) {
			trace("\t"+prop+":\t"+infoObject[prop]);
		}
		trace("Loaded: " + this.bytesLoaded);
		trace("bytesTotal: " + this.bytesTotal);
		trace("");
	};
};

loadMovieClip();
marcusw02 is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
netstream - looping video skjc ActionScript 2.0 0 10-04-2005 12:10 PM
Create a video object seby ActionScript 2.0 2 04-01-2005 07:24 AM
Attach sound object to netstream or video object grizjr ActionScript 2.0 2 03-28-2005 08:29 PM
Accessing Embedded Video object in custom component cbriarnold Components 0 01-11-2005 08:30 PM
Loading Video kcbobacey ActionScript 1.0 (and below) 6 01-16-2003 05:50 AM


All times are GMT. The time now is 10:30 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.