为什么我在尝试在流式视频播放器中搜索时出错

时间:2010-01-28 17:50:59

标签: flash actionscript-3 streaming progress-bar seek

我正在这里制作一个视频播放器:http://leongaban.com/stackoverflow/RTMP/

这是流式RTMP,如果用户点击凹槽条(绿色进度条下方的灰色条),我正试图让我的视频正确搜索目前它没有寻找并给我一个持续时间变量的NaN并且我的进度条宽度变量出错,这让我很困惑。

alt text

由于某种原因,我的 videoDuration变量在我的导引头函数中使用时会出现NaN ,在尝试追踪playerCntrls.progressTotalW时,我也得到一个空对象引用错误凹槽杆的总宽度:

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;
}

[痕量]

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

但是在我的updateDisplay函数中,我没有得到任何跟踪或使用相同变量的错误:

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);
}

这是我设置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链接到我的PlayerControls.as

public var playerCntrls:PlayerControls;

PlayerControls.as

现在我在我的PlayerControls.as中添加一个EventListener来调用我的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);
    }

任何提示或建议将不胜感激! :)

1 个答案:

答案 0 :(得分:1)

在PlayerControl类的上下文中调用seeker函数,一般来说,为事件侦听器设置其他类的函数并不是一个好习惯。你试试这个:

...
groove.addEventListener(MouseEvent.MOUSE_UP, onGrooveClick);
...
private function onGrooveClick(e:MouseEvent):void {
  videoDsply.seeker(mouseX);
}
并且在VideoDisplay中相应地修改了导引头功能。