Next Page

Page: 1

Previous Page

Thread: Buffering

Created on: 05/14/08 10:56 AM

Replies: 10

feklee





Joined: 05/14/08

Posts: 13

Buffering
05/14/08 10:56 AM

I'm currently developing an AS3 video player that talks with FMS, and I want to display how much of a video is already buffered (downloaded). It's just the usual display known from almost every video player out there.

What may be a good solution?

And: Is there any good documentation on building video players with the latest AS and FMS? Currently, there are too many issues were I rely on guessing.

- Felix

PS: What I already tried was using stream.time + stream.bufferLength as an indicator on how far the video is buffered. However, I fear that this indicator is not correct since (1) it doesn't advance smoothly at all and (2) it sometimes even slightly moves in the opposite direction.

Link | Top | Bottom

Graeme



Graeme's Gravatar

Joined: 10/18/07

Posts: 1107

RE: Buffering
05/19/08 11:03 AM

Depending on the type of video you are using (variable or constant bit) and the speed of the network, you could very likely see very sporadic increments and losses of "downloaded" video. The stream time plus buffer length should work as long as you know the total length of the video. Don't have code handy at the moment, but it sounds like a decent tutorial idea :)

Link | Top | Bottom

feklee





Joined: 05/14/08

Posts: 13

RE: Buffering
05/19/08 11:09 PM

Thanks for the input!

Concerning type of video: It's MP4 streamed from the FMS3 demo directory /opt/adobe/fms/application/vod/media.

Concerning stream time + buffer length:

1. A workaround to make the display nicer/smoother would probably be to average over a short period of time. I may implement that.

2. Couldn't it be that the buffer also contains frames that have already been displayed? Maybe these frames get discarded at regular time intervals. If that is the case, then that could explain why the buffering display sometimes jumps back. And it also would mean that stream time + buffer length is inaccurate.

Link | Top | Bottom

Graeme



Graeme's Gravatar

Joined: 10/18/07

Posts: 1107

RE: Buffering
05/21/08 9:53 PM

A tutorial for your perusal


It's in AS2, but I think you can get the idea.

Link | Top | Bottom

feklee





Joined: 05/14/08

Posts: 13

RE: Buffering
05/27/08 8:10 AM

Incredible, thanks a lot!

Sorry for not answering earlier. I was busy with another project and didn't have the time and patience to dabble with the video stuff. I'll now try to find out why my buffering bar is not so smooth. Could be that I should just increase buffering time. If I don't find a solution, I guess I'll just average a bit over time to get a smoother (but slightly incorrect) display.

- Felix

Link | Top | Bottom

jerome





Joined: 01/29/08

Posts: 120

RE: Buffering
05/28/08 3:21 AM

Does this works for Live Stream playing ?

Link | Top | Bottom

Graeme



Graeme's Gravatar

Joined: 10/18/07

Posts: 1107

RE: Buffering
05/30/08 1:42 PM

No.

Link | Top | Bottom

roblesedu





Joined: 12/08/08

Posts: 1

RE: Buffering
12/08/08 8:00 AM

CODE
var nc:NetConnection
var ns:NetStream
var streamLength:Number;
nc = new NetConnection();

nc.onStatus = function(info){
trace(info.code);
if(info.code.indexOf("Success") != -1) {
getStream();
}
}

function getStream(){
ns = new NetStream(nc);
ns.onMetaData = function(info){
streamLength = info.duration;
}
vid.attachVideo(ns);
ns.onStatus = function(info){
trace("ns status: " + info.code);
}
ns.setBufferTime(5);
//ns.play("BCLionsStreetParty2007v1");
ns.play("col");
startUpApp()
}

function startUpApp() {
_root.onEnterFrame = function(){

bufferLengthText.text = ns.bufferLength;
timeText.text = Math.round(ns.time * 100) / 100;

var total = Math.round((ns.time + ns.bufferLength) * 100) / 100;

var perc = Math.round((total / streamLength) * 10000 ) / 100;
var percWatched = Math.round((ns.time / streamLength) * 10000) / 100;
percentWatchedText.text = percWatched;
percentLoadedText.text = perc;

progressBar.scrubber._x = 320 * (percWatched / 100);
progressBar.bufferBar._width = 320 * (perc / 100);
}
}

progressBar.bufferBar._width = 0;
nc.connect("rmtp://205.234.239.103/fmsgurubuffertutorial/tutorial");

In implementing the following errors were made:

Line 15: Access of possibly undefined property onMetaData through a reference with static type flash.net:NetStream.

Line 18: Call to a possibly undefined method attachVideo through a reference with static type flash.media:Video.

Line 19: Attempted access of inaccessible property onStatus through a reference with static type flash.net:NetStream.

Line 22: Call to a possibly undefined method setBufferTime through a reference with static type flash.net:NetStream.

Line 29: Access of undefined property _root.

Line 31: Implicit coercion of a value of type Number to an unrelated type String.

Line 32: Implicit coercion of a value of type Number to an unrelated type String.

Line 6: Access of possibly undefined property onStatus through a reference with static type flash.net:NetConnection.

I could not identify the error!

Link | Top | Bottom

Graeme



Graeme's Gravatar

Joined: 10/18/07

Posts: 1107

RE: Buffering
12/11/08 2:20 PM

There are lots of errors there. You need to study up on AS3 or change your publish settings to AS2. For AS3 there are a lot of extra hoops to jump through to get things to work as easily as they did in AS2. Makes it more robust I suppose, but more work for almost the same result.

Link | Top | Bottom

pannonij





Joined: 02/04/10

Posts: 3

RE: Buffering
02/06/10 10:15 PM

AS3 version

//stream length
private var streamLength_num:Number;
//use a custom client object on nc to get metaDataHandler
private function metaDataHandler(info:Object):void {
//stores meta data in a object
objInfo = info;
//set stream length
streamLength_num = info.duration;
// now we can start the timer because
// we have all the neccesary data
tmrDisplay.start();
}
//in ENTER_FRAME or TIMER
var total:Number = Math.round((nsStream.time + nsStream.bufferLength) * 100) / 100;
var perc:Number = Math.round((total / streamLength_num) * 10000) / 100;
//185 = buffer bar width	videoPlayer.videoControl.scrollBar_mc.bufferBar_mc.width	= 185 * (perc / 100);

Link | Top | Bottom

daneco





Joined: 11/05/09

Posts: 5

RE: Buffering
02/18/10 2:01 AM

Graeme, do you know how to get the time played on a live flv stream, i did your tutorial on playing an flv as a live stream and i have it working great, i am wondering how i can just attach the amount of time the flv has been playing.
displaying something like 0:00:00/hours:minuets:seconds

thanks
daneco

Link | Top | Bottom

New Post

Please login to post a response.