Search code examples
flashactionscript-3flv

Stop Button Functionaliity while in BUFFERING_STATE_ENTERED


I have a video player that when buttons are pressed a video loads and plays. Every once in a while when I button mash I am able to get mulitple videos playing at once. I thought I had set the code up to remove all children before loading another video.

I have a feeling that my issues can ultimatly be fixed using the BUFFERING_STATE_ENTERED listener.

Is there a good way to disable all buttons on the screen while BUFFERING_STATE_ENTERED is active and turn everything back on once BUFFERING_STATE_ENTERED is complete?

//AS A QUICK FIX I AM LOADING A TRANSPARENT IMAGE OVER MY BUTTON AREA AND REMOVING THE IMAGE ON START, PUTTING IT BACK WHEN THE USER SELECTS A NEW VIDEO AND IT GOES INTO BUFFER_STATE_ENTERED. THIS KEEPS THEM FROM HITTING BUTTONS. THIS WAS NOT MEANT TO BE PERMANENT.**

var ButtonBlock:empty_png = new empty_png;
ButtonBlock.x = 1550;
my_player.addEventListener(VideoEvent.BUFFERING_STATE_ENTERED, bufferPlay);
function bufferPlay(e:VideoEvent):void {
        trace("IN BUFFER");
        addChild(ButtonBlock);
}   
my_player.addEventListener(VideoEvent.PLAYING_STATE_ENTERED, startPlay);
function startPlay(e:VideoEvent):void {


        if(ButtonBlock)
            {
            removeChild(ButtonBlock);
            }
}

Solution

  • My thought would be to disable the ability to select another video as soon as you select one, and re-enable it once you're ready for the user to select another one. I don't know how your program is set up, so some more info there would be useful.

    If you have several buttons, one for each video, then I would suggest simply having a boolean that each button checks before doing anything when clicked. Let's call it loadingVideo.

    if(!loadingVideo) {
        loadingVideo = true;
        //(button's actions here)
    } else {
        //(maybe a warning message here)
    }
    

    Once the video is initialized (maybe VideoEvent.PLAYING_STATE_ENTERED), you'll need to set loadingVideo to false again. That way if your user wants to change videos they can.