Skip to main content
Inspiring
August 17, 2011
Answered

video autoplay

  • August 17, 2011
  • 2 replies
  • 1363 views

How to add autoplay Video to this script

function playClicked(e:MouseEvent):void

{

     if(!bolLoaded)

     {

          stream.play(videoURL);

          bolLoaded = true;

     }

     else

     {

          stream.resume();

     }

     

     vidDisplay.visible = true;

     

     mcVideoControls.btnPause.visible = true;

     mcVideoControls.btnPlay.visible     = false;

     btnMidPlay.visible = false;

}

This topic has been closed for replies.
Correct answer relaxatraja

function connectStream():void
{
    stream = new NetStream(connection);
    stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
    stream.client = this;
    stream.bufferTime = BUFFER_TIME;
   
    vidDisplay.attachNetStream(stream);
   mcVideoControls.btnPause.visible = true;
    mcVideoControls.btnPlay.visible    = false;
    bolLoaded=true;

    stream.play(videoURL);
    addChild(vidDisplay);
    vidDisplay.smoothing = SMOOTHING;
}

see, actually you needed an play button on the whole screen before, what about that now? last time your requirement is to not play automatically, but now you required, so again the code should change.

2 replies

relaxatraja
Inspiring
August 18, 2011

function connectStream():void
{
    stream = new NetStream(connection);
    stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
    stream.client = this;
    stream.bufferTime = BUFFER_TIME;
   
    vidDisplay.attachNetStream(stream);
   stream.play(videoURL);
    addChild(vidDisplay);
    vidDisplay.smoothing = SMOOTHING;
}

Inspiring
August 18, 2011

function connectStream():void

{

     stream = new NetStream(connection);

     stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);

     stream.client = this;

     stream.bufferTime = BUFFER_TIME;

    

     vidDisplay.attachNetStream(stream);

     stream.play(videoURL);

     addChild(vidDisplay);

     vidDisplay.smoothing = SMOOTHING;

}

function playClicked(e:MouseEvent):void

{

    

     if(!bolLoaded)

     {

          //stream.play(videoURL);

          bolLoaded = true;

     }

     else

     {

          stream.resume();

     }

    

     vidDisplay.visible = true;

    

     mcVideoControls.btnPause.visible = true;

     mcVideoControls.btnPlay.visible     = false;

     btnMidPlay.visible = false;

}

function pauseClicked(e:MouseEvent):void {

     stream.pause();

    

     mcVideoControls.btnPause.visible     = false;

     mcVideoControls.btnPlay.visible          = true;

     btnMidPlay.visible = true;

}

Now autoplay Fine, But first time "play" working after "pause" notworking; then after play&pause working fine.

What is the problem?

relaxatraja
relaxatrajaCorrect answer
Inspiring
August 18, 2011

function connectStream():void
{
    stream = new NetStream(connection);
    stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
    stream.client = this;
    stream.bufferTime = BUFFER_TIME;
   
    vidDisplay.attachNetStream(stream);
   mcVideoControls.btnPause.visible = true;
    mcVideoControls.btnPlay.visible    = false;
    bolLoaded=true;

    stream.play(videoURL);
    addChild(vidDisplay);
    vidDisplay.smoothing = SMOOTHING;
}

see, actually you needed an play button on the whole screen before, what about that now? last time your requirement is to not play automatically, but now you required, so again the code should change.

Ned Murphy
Legend
August 17, 2011

Adding autoplay to that particular script will probably not get very far since that script won't execute until a mouse interaction with something triggers it.  If you are using the Netstream class, then you probably just want to have the

stream.play(videoURL);

line by itself outside the function just after the stream is defined.