Skip to main content
Participant
November 13, 2008
Question

Problem with increasing stream delay time on client

  • November 13, 2008
  • 1 reply
  • 439 views
Hi,
Iam having this problem:
Iam running tv-like app which streams bunch of videos; after last video in row finishes, app loads new videoloop from xml and starts stream again. When a client connects, everything works just fine with 1 exception: the clients stream is slowly increasing delay from source. Ive tried to check netStream.bufferLength during playing (its set to 3s on the beginning) and i found out, thats its slowly growing. - after like 5 minutes of playing its around 30s; my only suggestion is, that client isnt playing video fast enough... which sounds kinda stupid to me... (ive checked this on many systems / networks and iam pretty sure it has nothing to do with processor/network overload) please, anyone could have solution for this ?Any help would be highly appreciated.

Thanks,
J.S.

Application code is here:

application.allowDebug = true;

application.onAppStart = function() {
trace("STREAM>>> Application TV stream started");

application.loopArray = new Array();
application.videoIndex = -1;

application.clientStream = Stream.get("tvStream");

loadXml("loop.xml");

application.clientStream.onStatus = function(str) {
switch (str.code) {
case "NetStream.Play.Stop":
loadXml("loop.xml");
break;
case "NetStream.Play.Start":
application.videoIndex++;
trace("STREAM>>> playing video "+application.loopArray[application.videoIndex][0]+" videoindex= "+application.videoIndex);
break;
case "NetStream.Play.Reset":
application.videoIndex = -1;
trace("STREAM>>> Stream restarted");
break;
}
//trace(str.code);
}

function setStream(vidArray) {
for (var i=0;i<vidArray.length;i++) {
var repeat=false;
/*if (i==0) {
repeat = true;
} else {
repeat = false;
}*/
application.clientStream.play(vidArray [0],0,-1,repeat);
}
}

function loadXml(target2load) {
application.loopArray = new Array();
var xml = new XML();
xml.ignoreWhite = true;
xml.onLoad = function(succes) {
for (var i = 0; i < xml.firstChild.childNodes.length; i++) {
application.loopArray
= new Array();
application.loopArray .push(xml.firstChild.childNodes.attributes.poradpath);
application.loopArray .push(xml.firstChild.childNodes.attributes.id);
application.loopArray .push(xml.firstChild.childNodes.attributes.desc);
application.loopArray .push(xml.firstChild.childNodes.attributes.name);
application.loopArray .push(xml.firstChild.childNodes.attributes.dil);
}
application.videoIndex = -1;
setStream(application.loopArray);
trace("SERVER>>> XML loaded - starting stream");
}
xml.load(target2load);
}

}

application.onConnect = function(clientObj) {
application.acceptConnection(clientObj);
clientObj.call("getPlayedFileInfo",null,application.setVidInfo());
// trace("CLIENT>>> Client connected: IP="+clientObj.ip+" | ID="+clientObj.id+" | referrer="+clientObj.referrer);
}

application.onDisconnect = function(clientObj) {
// trace("CLIENT>>> Client disconnected: IP="+clientObj.ip+" | ID="+clientObj.id);
}

application.setVidInfo = function() {
// trace(application.loopArray[application.videoIndex]);
return application.loopArray[application.videoIndex].slice(1,application.loopArray[application.videoIndex].length);
}

Client.prototype.sendVidInfo = function() {
this.call("getPlayedFileInfo",null,application.setVidInfo());
}
    This topic has been closed for replies.

    1 reply

    November 13, 2008
    Hmm... I'm not sure if it was fixed in FMS3, but I had exactly the same problem with FMS2. It turned out there was a bug in the Stream.play method that caused problems when setting the reset flag to true.

    It was quite a while ago, but I remember the fix being twofold. First, you need to define an actual length in the length flag (instead of using -1), and you need to supply a string (any string) as the value of the virtual key flag. So, you'd need to do something like this:

    application.clientStream.play(vidArray ,0,300,repeat, "someString");

    Of course, that means you need to make your code aware of the length of each video before playing it.

    For my purposes that didn't work so well (some of the source streams were live), so I took a sort of hackish approach. Each time the video source was to change, I invoke a method on all of the clients that closes the stream and reopens it. That fixed the delay for me.

    IakoopAuthor
    Participant
    November 14, 2008
    Thanks for answer, but i dont think this could solve my problem;

    1) Right now, i dont use repeat=true in stream.play() method, when the stream stops, i just reload xml and start to play the "new" stream.

    2) In fms3 documentation, play method looks like this: public play(name : Object [,start : Number[, len : Number[, reset : Object]]]), when i add last parameter as you suggest, application starts, but stream doesent.

    3) About the hackish approach you describe, doesent that also mean that when client reopens the stream when source changes, it will cut the actually played video and starts to play the new one ?
    IakoopAuthor
    Participant
    November 14, 2008
    Oh, nevermind ad 2, ive mistaken Stream and NetStream class