Seek based on mouse click

422 Views Asked by At

I am trying to modify the Strobe media playback to seek across a video based on mouse clicks on a button and not on the control bar. Each click should take me ahead by 'n' seconds and the it should clear the buffer and insert the correct fragments automatically.

To do this, I have a function which is triggered based on when the button is clicked, but I'm not able to seek. I get a error: cannot access a property or method of a null object reference

Can someone tell me whats wrong here:

        override protected function onMouseClick(event:MouseEvent):void
    {

        httpStreamSource.seek(9);
//          mediaPlayer.seek(55);

        showRight = !showRight;
        if(showRight)
            setFace(down);
        else
            setFace(up);
    }

Thanks in advance!

1

There are 1 best solutions below

1
On BEST ANSWER

for seek n-seconds ahead you should take current time add n-seconds and feed this to seek method.

for your null object error you MUST make sure that the object exists:

TypeError: Error #1009: Cannot access a property or method of a null object reference.at org.osmf.player.chrome.widgets::JumpButton/_seekVideo()[I:\OSMF\player\StrobeMed‌​iaPlayback\src\org\osmf\player\chrome\widgets\JumpButton.as:49]

at line 49 you have only one object: mediaPlayer - add test if it exists before using it:

private function _seekVideo( seekTo : Number ):void 
{ 
    if (mediaPlayer && mediaPlayer.canSeekTo(seekTo * mediaPlayer.duration))
    {
        mediaPlayer.seek( seekTo * mediaPlayer.duration );//line49 
    }
}

this will prevent the TypeError you should innvestigate why the mediaPlayer object is not available at the time you click on it.

best regards