views:

89

answers:

1

I'm building a video player here: http://leongaban.com/stackoverflow/RTMP/

It's streaming RTMP, and I'm trying to get my video to seek correctly if the user clicks on the groove bar (gray bar under the green progress bar) Currently it does not seek and gives me a NaN on my duration variable and an error on my progress bar width variable, which is puzzling me.

alt text

For some reason my videoDuration variable is coming up as NaN when used inside of my seeker function, also I'm getting a null object reference error when trying to trace out playerCntrls.progressTotalW which is the total width of the groove bar:

VideoDisplay.as

public function seeker(e:MouseEvent):void
{
    trace("clicked the groove bar");
    trace("mouseX = "+mouseX);
    trace("videoDuration = "+videoDuration);
    trace("playerCntrls.progressTotalW = "+playerCntrls.progressTotalW);

    ns.seek(Math.round(mouseX * videoDuration / playerCntrls.progressTotalW));
    playerCntrls.progressBar.width = mouseX * playerCntrls.progressTotalW / videoDuration;
}

[TRACES]

clicked the groove bar
mouseX = 135
videoDuration = NaN
TypeError: Error #1009: Cannot access a property or method of a null object reference.

However in my updateDisplay function I don't get any errors tracing or using those same variables:

private function updateDisplay(e:TimerEvent):void
{
   currentTime = ns.time;
   currentFormattedTime = convertTime(currentTime);

   playerCntrls.updateTime();
   playerCntrls.progressBar.width = ns.time * playerCntrls.progressTotalW / videoDuration;
   trace("videoDuration = "+videoDuration);
   trace("ns.time        = "+ns.time);
   trace("Progress Width = "+playerCntrls.progressBar.width);
}

This is where I set the videoDuration var:

function getMetaData(client_ns) 
{
    var metaData:Object = new Object();
    metaData.onMetaData = function(metaData:Object):void 
    {

    videoDuration = metaData.duration;
    trace("metadata duration = "+videoDuration);

    tmrDisplay.start();
    }
    return client_ns.client = metaData;
}

playerCntrls links to my PlayerControls.as

public var playerCntrls:PlayerControls;

PlayerControls.as

Now this is where I add an EventListener in my PlayerControls.as to call the seeker function in my VideoDisplay.as

// Create Progress Bar ··········································
    public function createProgress():void
    {
        progressBar               = new ProgBar;
        progressBar.mouseEnabled  = false;
        progressBar.mouseChildren = false;

        progressBar.x     = grooveX;
        progressBar.y     = grooveY;
        progressBar.width = 1;

        progressBar_color = progressBar.colorChip;
        TweenLite.to(progressBar_color, .1, {tint:xmlColor});
        controls.addChild(groove);
        controls.addChild(progressBar);

        groove.addEventListener(MouseEvent.MOUSE_UP, videoDsply.seeker);
    }

Any tips or advice would be greatly appreciated! :)

+1  A: 
bhups
WOOT! Yeah that fixed it :) http://leongaban.com/stackoverflow/RTMP/ Now I just gotta play with the numbers a bit, the progress bar jumps a bit then goes to the right spot, but at least it's seeking correctly now :D thanks!
Leon