Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FLV loading progress

Status
Not open for further replies.

moleproductions

Programmer
Oct 23, 2003
43
GB
Hi,

I have been struggling with this issue for some time now. I have searched Google as well as this an other forums and haven't yet found a suitable solution. I know there is someone out there who can help as I have seen this hundreds of times before!

I have a page that loads an FLV video. At the moment it uses the built in FLV player component, but I could just as easily use AS3 to add the video to a video sprite.

However, what I would like to do is to show some form of loading graphic while the video is buffering - and have some control over how much of the video is buffered before it starts to play. The videos range from a few minutes to 45 minutes - so I need some flexibility.

I found this for AS2 - but I need AS3:

I've tried to use something like the following, but I no control.

Code:
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
videoPlayer.attachVideo(ns);
ns.play("externalVideo.flv");

Can anyone help?
Thanks.
 
Thanks kennethkawamoto - that's really useful.

However, I can't seem to find how to use that - do you have some kind of example of how it is used? Whenever I try to use this, it never works.

Thanks.
 
Thanks - but I am really struggling here. I have tried what you suggest - and indeed it works!

But now I just can't get this to work. The section
Code:
ns.addEventListener(ProgressEvent.PROGRESS, handleProgress);
just will not work below. Any thoughts?


Code:
var videoPlayer:Video = new Video(270, 320);
var VideoPreload:String = "";
var trackWidth:Number = track.width;

var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
var client:Object = new Object(  );
client.onMetaData = onMetaData;
ns.client = client;
ns.addEventListener(ProgressEvent.PROGRESS, handleProgress);
ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
ns.bufferTime = 10;
videoPlayer.attachNetStream(ns);
addChild(videoPlayer);
ns.play("video.flv");

function handleProgress(event:ProgressEvent):void {
	var percent:Number = Math.round( event.bytesLoaded/event.bytesTotal * 100 );
	VideoPreload = "Loaded: " + event.bytesLoaded + "\n"
	+ "  Total: " + event.bytesTotal + "\n"
	+ "Percent: " + percent;
	trace(VideoPreload);
	
	knob.x = 222 + ((percent / 100) * trackWidth);
	trace (knob.x);
}

function asyncErrorHandler(event:AsyncErrorEvent):void {
	trace(event.text);
}

function onMetaData(data:Object):void {
	trace(data.duration + " seconds long");
}
 
It will not work because [tt]NetStream[/tt] does not dispatch [tt]progress[/tt] event :)

You can either use [tt]FLVPlayback[/tt], which dispatches [tt]progress[/tt] event, or run a [tt]Timer[/tt] (or on [tt]enterFrame[/tt]) to check [tt]bytesLoaded[/tt] - if I were you I'd use [tt]FLVPlayback[/tt] because simply it requires less coding and I have limited time to deliver the goods, unless I have compelling reason to use [tt]NetStream[/tt] (...and this happened to me once ;)

Kenneth Kawamoto
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top