开发者

Why am I getting error while trying to seek in my streaming video player

开发者 https://www.devze.com 2022-12-18 14:07 出处:网络
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 unde

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.

Why am I getting error while trying to seek in my streaming video player

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);
        contr开发者_StackOverflow社区ols.addChild(progressBar);

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

Any tips or advice would be greatly appreciated! :)


seeker function is being called in context of PlayerControl class and in general it is not good practice to set some other class's function for event listeners. You try this out:

...
groove.addEventListener(MouseEvent.MOUSE_UP, onGrooveClick);
...
private function onGrooveClick(e:MouseEvent):void {
  videoDsply.seeker(mouseX);
}
And in VideoDisplay modify the seeker function accordingly.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号