Skip to main content
Participant
April 20, 2007
Question

Video stream halts every few seconds

  • April 20, 2007
  • 1 reply
  • 691 views
Hello, all.

I'm having some problems with odd pauses creeping into our video streams. What happens is that the server streams out data to the clients (which are on various websites and other physical servers than our FMS box), but then stops streaming for some reason. The clients then reconnect, but there is a noticeable pause -- several seconds long -- while they do so. Tests so far have shown nothing in the logs (which are collecting all available data fields), despite the pauses showing up in the SWF files playing the video.

I'm using the workaround of telling the SWF to buffer the entire movie for now, but this places too high a load on the end-users' systems. Has anyone else here encountered a similar problem?
    This topic has been closed for replies.

    1 reply

    April 20, 2007
    If the problem occurs consistently, I would guess there's something going on in your actionscript that's causing it. If you post your code, it will be easier to find the problem.

    About buffering the entire video file, that's not a great idea unless the video is very short. Buffered data is held in RAM, so if you try to buffer a 2gb video file, you'll consume 2gb of RAM on the client side, and things like that lead to crashed browsers (and sometimes crashed OS's).
    Flat_CapAuthor
    Participant
    April 20, 2007
    quote:

    Originally posted by: JayCharles
    About buffering the entire video file, that's not a great idea unless the video is very short. Buffered data is held in RAM, so if you try to buffer a 2gb video file, you'll consume 2gb of RAM on the client side, and things like that lead to crashed browsers (and sometimes crashed OS's).

    I never said that it was a good workaround, nor one that I want to keep. :)

    Here's the code, which is a one-frame job:

    stop();

    function tell_length() {
    this.onResult = function (returned) {
    _root.totaltime = returned;
    output = format_time(returned);
    progressBar_mc.time_total.replaceText(0,progressBar_mc.time_total.length, output);
    // format has to be reset in order to display the text
    progressBar_mc.time_total.setTextFormat(myformat);
    };
    function checkBytesLoaded() {
    progressBar_mc.time_now.replaceText(0,progressBar_mc.time_now.length, format_time(totaltime-my_stream.time));
    progressBar_mc.time_now.setTextFormat(myformat);
    _root.progressBar_mc.bar_mc._xscale = my_stream.time/_root.totaltime * 100;
    if (amdragging == false) {
    progressBar_mc.scrubber._x = ((my_stream.time/_root.totaltime) * 220) - 6.5;
    }
    if (_root.totaltime == my_stream.time) {
    clearInterval(loaded_interval);
    }
    }
    var loaded_interval:Number = setInterval(checkBytesLoaded, 500, my_stream);
    }

    function majorversion() {
    //get the major version of the player. We'll need 8+ for this to work
    verstring = System.capabilities.version;
    thisVer = verstring.split(",");
    thisVerSpaceNum = thisVer[0].indexOf(" ");
    //finally, a major version number (eg 6)
    thisMajorVer = Number(thisVer[0].substr(thisVerSpaceNum));
    return thisMajorVer;
    }

    function checkBytesLoaded() {
    //movie for this player is known to be 207.504s long
    var pctLoaded:Number = Math.round(_root.in_ns.time/207.504*100);
    _root.progressBar_mc.bar_mc._xscale = pctLoaded;
    if (pctLoaded>=100 && !isNaN(pctLoaded)) {
    clearInterval(loaded_interval);
    trace("checkBytesLoaded done");
    }
    }

    function playBackVideo() {
    // control path for pause/resume
    trace("play_status: "+play_status);
    if (play_status == "stop" || play_status == "play") {
    var loaded_interval:Number = setInterval(checkBytesLoaded, 500, in_ns);
    }
    if (play_status == "play") {
    _root.pp.gotoAndStop(2);
    //next command will be 'pause'
    play_status = "pause";
    in_ns.pause();
    return;
    } else if (play_status == "pause") {
    // next command will be "play"
    play_status = "play";
    _root.pp.gotoAndStop(1);
    in_ns.pause();
    return;
    }
    createConnection(my_nc);
    }

    function createConnection(nc) {
    NetConnection.prototype.onBWCheck = function() {
    return ++counter;
    // Serverside, just ignore any return value and return the call count
    };
    nc.fpadOnly = false;
    nc.fpadPort = Number(67);
    nc.fpadZone = Number(-1);//was 0: now "do not use FPAD"
    nc.connect("rtmp://video.fnord.co.uk/client/video/", true);
    createStream(nc);
    }
    function createStream(nc) {
    prefix = "";
    if (_root.availbandwidth >450) {
    buffertime = 3;
    prefix = "400";
    } else {
    buffertime = 10;
    prefix = "100";
    }
    buffertime = 5;
    prefix = "400";

    in_ns = new NetStream(nc);
    in_ns.setBufferTime(buffertime);
    // set short buffer to get metadata - was 1/10, but let's increase it
    play_video.attachVideo(in_ns);
    if (_root.whichmovie == undefined) {
    _root.whichmovie = "fnord_";
    }
    nowplaying = _root.whichmovie + prefix;
    // trace("movie name: " + nowplaying);

    in_ns.play(nowplaying, 0);
    // trace(in_ns.bytesTotal);

    in_ns.onPlayStatus = function(info_object){
    if (info_object.code == "NetStream.Play.Complete") {
    stopPlayBack();
    }
    }
    in_ns.onStatus = function(info) {
    if(info.code == "NetConnection.Connect.Success"){
    in_ns.call("getStreamLength", new tell_length(), _root.whichmovie);
    }
    if (info.code == "NetStream.Play.Stop") {
    play_status = "stop";
    }
    if (info.code == "NetStream.Play.Start") {
    play_status = "play";
    }
    if (info.code == "NetStream.Buffer.Full") {
    _root.buffy._visible = false;
    my_timer = new Date();
    newbuffer = _root.in_ns.bufferTime * 2
    trace(my_timer.getHours()+":"+my_timer.getMinutes()+":"+my_timer.getSeconds()+"."+my_timer.getMilliseconds()+" buffer full, setting buffertime to "+newbuffer);
    in_ns.setBufferTime(newbuffer);
    }
    if (info.code == "NetStream.Buffer.Empty") {
    _root.buffy._visible = true;
    my_timer = new Date();
    trace(my_timer.getHours()+":"+my_timer.getMinutes()+":"+my_timer.getSeconds()+"."+my_timer.getMilliseconds()+" buffer empty, setting buffertime to 2");
    in_ns.setBufferTime(2);
    }
    /*Netstream.Play.Complete is called by onPLAYstatus, not onStatus. */
    };
    // It's new to FMS 2 status event
    // NetStream.Play.Complete event and etc are captured
    in_ns.onMetaData = function(info) {
    video_duration = info.duration;
    if (autoSize_cb.selected && info.width && info.height) {
    video_width = play_video._width;
    video_height = play_video._height;
    play_video._width = info.width;
    play_video._height = info.height;
    } else {
    video_width = info.width;
    video_height = info.height;
    }
    };
    }

    function stopPlayBack() {
    trace("Playback stopped at "+in_ns.time);
    my_nc.close();
    play_status = "stop";
    //show play button
    _root.pp.gotoAndStop(2);
    _root.progressBar_mc.bar_mc._xscale = 0;
    clearInterval(loaded_interval);
    in_ns.setBufferTime(0)
    }

    if (_root.introtext == undefined) {
    _root.introtext = "fnord";
    }

    if(majorversion() < 8) {
    gotoAndStop(2);
    }

    //test connection speed
    nc = new NetConnection();
    NetConnection.prototype.onBWDone = function(p_bw) {
    // app logic based on the bandwidth detected follows here
    _root.availbandwidth = p_bw;
    // close the Netconnection to bwcheck
    this.close();
    }
    NetConnection.prototype.onBWCheck = function() {
    return ++counter; // Serverside, just ignore any return value, For now return the call count
    }
    nc.connect("rtmp://video.fnord.co.uk/bwcheck", true);

    //tween the title in
    import mx.transitions.Tween;
    import mx.transitions.easing.*;
    import flash.filters.GlowFilter;
    var iTweenObject:Number;
    var theTween:Object;
    var timeline:MovieClip = this;
    //this.bitbox.introbit._alpha = 50;
    theTween = new Tween(bitbox, "_alpha", Regular.easeOut, 5, 100, 3, true);
    theTween.onMotionFinished = function() {
    theOtherTween = new Tween(bitbox, "_alpha", Regular.easeOut, 100, 0, 1, true);
    theOtherTween.onMotionFinished = function() {
    theglow = new GlowFilter(0xffffff, .50, 10, 10, 1, 2, false, false);
    _root.gogogo.filters = new Array(theglow);//_y = 105.5;
    };
    };

    //initialize buffer monitoring bar
    var video_duration;
    var video_width;
    var video_height;
    var progress_interval;
    var play_status = "stop";
    var my_nc = new NetConnection();
    var in_ns;

    /*progress bar*/
    _root.createEmptyMovieClip("progressBar_mc", this.getNextHighestDepth());
    progressBar_mc._x = 200;
    progressBar_mc._y = 355;

    progressBar_mc.createEmptyMovieClip("bar_mc", progressBar_mc.getNextHighestDepth());
    with (progressBar_mc.bar_mc) {
    beginFill(0xFF6600);
    moveTo(0, 0);
    lineTo(200, 0);
    lineTo(200, 10);
    lineTo(0, 10);
    lineTo(0, 0);
    endFill();
    _xscale = 0;
    }

    progressBar_mc.createEmptyMovieClip("stroke_mc", progressBar_mc.getNextHighestDepth());
    with (progressBar_mc.stroke_mc) {
    lineStyle(0, 0x000000);
    moveTo(0, 0);
    lineTo(200, 0);
    lineTo(200, 10);
    lineTo(0, 10);
    lineTo(0, 0);
    }

    playBackVideo();

    Its ancestors have worked without problems in the past, so I find myself wodering whether the server settings are the problem.
    Flat_CapAuthor
    Participant
    April 24, 2007
    Any thoughts?