Skip to main content
Known Participant
June 25, 2019
Answered

Loop an externally linked video

  • June 25, 2019
  • 1 reply
  • 510 views

Hello,

I would lile to endlessly loop a externally linked video file which acts as a background layer.

Here is my current functioning code :

import flash.net.NetConnection;

import flash.net.NetStream;

var myConnection:NetConnection = new NetConnection();

var myStream:NetStream;

var metaInfo:Object = new Object();

myConnection.connect(null);

myStream = new NetStream(myConnection);

myVideo.attachNetStream(myStream);

myStream.play("myVideo.mp4");

metaInfo.onMetaData = onMetaData;

myStream.client = metaInfo;

function onMetaData(info:Object):void{

}

How can unable the video for it to loop seamlessly?

Thanks in advance!

This topic has been closed for replies.
Correct answer kglad

Thanks, I'm slowly getting there. Sorry, I'm new to AS3.

Using import flash.events.VideoEvent and + the netstream instead of video.

Calling completeF from statushandler is an other story. Here's what I currently have :

import flash.events.VideoEvent

myStream.addEventListener(NetStatusEvent.NET_STATUS, statusHandler);

function statusHandler(event:NetStatusEvent):void{

    switch (event.info.code)

    {

        case "NetStream.Play.Start":

            trace("Start [" + myStream.time.toFixed(3) + " seconds]");

            break;

        case "NetStream.Play.Stop":

            trace("Stop [" + myStream.time.toFixed(3) + " seconds]");

            break;

    }

}

// TRYING TO CALL statusHandler FUNCTION with : myStream.addEventListener(Event.CONNECT,statusHandler)

myStream.addEventListener(Event.CONNECT,statusHandler)

function completeF(e: flash.events.VideoEvent): void {

    myStream.seek(0);

    myStream.play();

}


use:

function statusHandler(event: NetStatusEvent): void {

switch (event.info.code) {

case "NetStream.Play.Start":

trace("Start [" + myStream.time.toFixed(3) + " seconds]");

break;

case "NetStream.Play.Stop":

trace("Stop [" + myStream.time.toFixed(3) + " seconds]");

completeF(event);

break;

}

}

function completeF(e: Event): void {

myStream.seek(0)

myStream.play(("séquence_justice.mp4");

}

1 reply

kglad
Community Expert
Community Expert
June 26, 2019

you can check for the end of your netstream and then restart it but it won't be seamless unless you edit the end of the video to go black.

Known Participant
June 26, 2019

I have pinpointed the end of the NetStream but I can't seem to find a way to restart it. Here is my current code:

myConnection.connect(null);

myStream = new NetStream(myConnection);

séquence_justice.attachNetStream(myStream);

myStream.play("séquence_justice.mp4");

metaInfo.onMetaData = onMetaData;

myStream.client = metaInfo;

function onMetaData(info:Object):void{

}

myStream.addEventListener(NetStatusEvent.NET_STATUS, statusHandler);

function statusHandler(event:NetStatusEvent):void

{

    switch (event.info.code)

    {

        case "NetStream.Play.Start":

            trace("Start [" + myStream.time.toFixed(3) + " seconds]");

            break;

        case "NetStream.Play.Stop":

            trace("Stop [" + myStream.time.toFixed(3) + " seconds]");

            break;

    }

}

The output information I get form this is the following:

Start [0.000 seconds]

Stop [33.433 seconds]

Thanks!

Legend
June 26, 2019