Hi, I have an application that take actions from a webcam to start a new video, the application is and MUST be an AIR application.
the all application is working smoothly but after a while the one of the 4 videos stop playing by himself.
The overlay video (a logo) still play smoothless, and when an action is captured from the webcam it correctly calls the action video, but when the action video is finished the, let's call it "still video" is blocked again at the same frame.
The problem is that is not happening always after 5 minutes, sometimes 5 sometimes 30 minutes and sometimes after few hours.
Attached is the code.
package src
{
import flash.display.MovieClip;
import flash.media.Video;
import flash.ui.Mouse;
import flash.media.Camera;
import flash.events.Event;
import src.uk.co.soulwire.cv.MotionTracker;
import com.greensock.loading.*;
import com.greensock.events.LoaderEvent;
import com.greensock.TweenMax;
import com.greensock.loading.data.VideoLoaderVars;
import com.greensock.loading.data.LoaderMaxVars;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import flash.display.Sprite;
import flash.utils.Timer;
import flash.events.TimerEvent;
//TOLGO L'IMPORTAZIONE DEL PROIETTORE
//import projector.Projector;
//import projector.ProjectorEvent;
import flash.desktop.NativeApplication;
public class Main extends MovieClip
{
private var spegnimento_mc:Spegnimento = new Spegnimento();
/* Variabili video */
private var arr_video_loop:Array = new Array();
private var arr_video_azione:Array = new Array();
private var mc:MovieClip;
private var indice:Number = 0;
private var language:String = '';
private var videoLoop_mc:MovieClip = new MovieClip();
private var videoAzione_1_mc:MovieClip = new MovieClip();
private var videoAzione_2_mc:MovieClip = new MovieClip();
private var videoLoop_vars:VideoLoaderVars = new VideoLoaderVars().centerRegistration(true).repeat(0).autoPlay(false).onComplete(caricaVideoLoop);
private var videoAzione_vars:VideoLoaderVars = new VideoLoaderVars().centerRegistration(true).autoPlay(false).onComplete(caricaVideoAzione);
private var videoLoop_1_ENG:VideoLoader = new VideoLoader("video/attesa 01 ENG.f4v", videoLoop_vars.name("ENG"));
private var videoLoop_1_ITA:VideoLoader = new VideoLoader("video/attesa ita 01.f4v", videoLoop_vars.name("ITA"));//attesa ita 01.f4v
private var videoLoop_2_ENG:VideoLoader = new VideoLoader("video/attesa 02 ENG.f4v", videoLoop_vars.name("ENG"));//attesa 02 ENG.f4v
private var videoLoop_2_ITA:VideoLoader = new VideoLoader("video/attesa ita 02.f4v", videoLoop_vars.name("ITA"));//attesa ita 02.f4v
private var videoAzione_1:VideoLoader = new VideoLoader("video/speech ENG.f4v", videoAzione_vars.name("ENG"));
private var videoAzione_2:VideoLoader = new VideoLoader("video/speech ITA.f4v", videoAzione_vars.name("ITA"));
/* Loader */
private var loader_vars:LoaderMaxVars = new LoaderMaxVars().onComplete(caricatiTutti).maxConnections(20);
private var loader:LoaderMax = new LoaderMax(loader_vars);
/* fine variabili video*/
private var _target:Sprite = new Sprite();
private var posX : Number = 0;
private var posY : Number = 0;
private var camW : int = 420;
private var camH : int = 320;
private var cam : Camera = new Camera();
private var teleCamera : Video = new Video(camW, camH);
private var telecamera_not_fount_timer:Timer = new Timer(15000);
private var timer_to_start:Timer = new Timer(10000);
private var _motionTracker : MotionTracker;
private var standbyMode : Boolean;
//tolgo la variabile proiettore
//private var proiettore: Projector;
private var impostazioniCaricati: Boolean;
//video attualmente visualizzato
private var videoCorrente:MovieClip;
private var timerAvviamento: Timer;
public function Main()
{
stage.addEventListener(KeyboardEvent.KEY_DOWN, addMenuSpegni);
timer_to_start.addEventListener(TimerEvent.TIMER, riprendiEvento);
//ENG
videoAzione_1.addASCuePoint(2, "BO_mc");
videoAzione_1.addASCuePoint(7, "FFT_mc");
//videoAzione_1.addASCuePoint(22, "BO_mc");
videoAzione_1.addEventListener(VideoLoader.VIDEO_CUE_POINT, playAnimazione);
//ITA
videoAzione_2.addASCuePoint(2, "BO_mc");
videoAzione_2.addASCuePoint(10, "FFT_mc");
//videoAzione_2.addASCuePoint(15, "BO_mc");
videoAzione_2.addEventListener(VideoLoader.VIDEO_CUE_POINT, playAnimazione);
videoLoop_1_ENG.addASCuePoint(26, "BO_mc");
videoLoop_1_ENG.addEventListener(VideoLoader.VIDEO_CUE_POINT, playAnimazione);
videoLoop_2_ENG.addASCuePoint(22, "BO_mc");
videoLoop_2_ENG.addEventListener(VideoLoader.VIDEO_CUE_POINT, playAnimazione);
videoLoop_1_ITA.addASCuePoint(22, "BO_mc");
videoLoop_1_ITA.addEventListener(VideoLoader.VIDEO_CUE_POINT, playAnimazione);
videoLoop_2_ITA.addASCuePoint(27, "BO_mc");
videoLoop_2_ITA.addEventListener(VideoLoader.VIDEO_CUE_POINT, playAnimazione);
loader.append(videoLoop_1_ENG);
loader.append(videoLoop_1_ITA);
loader.append(videoLoop_2_ENG);
loader.append(videoLoop_2_ITA);
loader.append(videoAzione_1);
loader.append(videoAzione_2);
loader.load();
//tolgo la chiamata projector();
//proiettore = new Projector();
//proiettore.addEventListener(ProjectorEvent.RUNNING_MODE, eventRunningMode);
//proiettore.addEventListener(ProjectorEvent.STANDBY_MODE, eventStandbyMode);
//proiettore.addEventListener(ProjectorEvent.SWITCHING_ON, eventSwitchingOn);
Mouse.hide();
//stage.addEventListener(KeyboardEvent.KEY_DOWN, noExit);
impostazioniCaricati = false;
timerAvviamento = new Timer(5000, 1); /*timerAvviamento = new Timer(10000, 1);*/
timerAvviamento.addEventListener(TimerEvent.TIMER, fineAvviamento);
timerAvviamento.start();
standbyMode = true;
} // Main
private function fineAvviamento(e){
TweenMax.to(videoCorrente.vd, 1, {volume:1});
standbyMode = false;
//trace("fineAvviamento - Richiamo caricaPosizione();");
//caricaPosizione();
}
private function addMenuSpegni(e:KeyboardEvent):void
{
if(String.fromCharCode(e.charCode) == "s" || String.fromCharCode(e.charCode) == "S")
{
if(menu_container_mc.contains(spegnimento_mc))
{
Mouse.hide();
menu_container_mc.removeChild(spegnimento_mc);
}
else
{
Mouse.show();
menu_container_mc.addChild(spegnimento_mc);
}
} //if(String.fromCharCode(e.charCode) == "s" || String.fromCharCode(e.charCode) == "S")
}
private function playAnimazione(e:LoaderEvent)
{
if(e.data.name == "BO_mc")
{
BO_mc.gotoAndPlay(2);
}
else
{
FFT_mc.gotoAndPlay(2);
}
}
private function riprendiEvento(e:TimerEvent)
{
timer_to_start.stop();
timer_to_start.reset();
this.addEventListener("azione", videoAzioneFunction);
}
private function onEnterFrameHandler(e:Event):void
{
_motionTracker.track();
_target.x = (_motionTracker.x);
_target.y = (_motionTracker.y );
if (_target.x != posX && _target.y != posY)
{
this.dispatchEvent(new Event("azione"));
}
posX = _target.x;
posY = _target.y;
}
private function videoAzioneFunction(e):void
{
if(standbyMode){
return; //evita che il totem cominci a reagire quando è in standby
}
this.removeEventListener("azione", videoAzioneFunction);
BO_mc.gotoAndStop(2);
trace(language);
if(language == "ENG")
{
for(var i in arr_video_loop)
{
if(container_mc.contains(arr_video_loop[i]))
{
this.fade_mc(arr_video_azione[1], arr_video_loop[i]);
}
}
}
else
{
for(var ii in arr_video_loop)
{
if(container_mc.contains(arr_video_loop[ii]))
{
this.fade_mc(arr_video_azione[0], arr_video_loop[ii]);
}
}
}
}
private function videoLoopFunction(e):void
{
timer_to_start.start();
var num:Number;
if(indice == arr_video_loop.length -1)
{
num = 3;
indice = 0;
}
else
{
num = indice;
indice++
}
language = arr_video_loop[indice].vd.name;
if(container_mc.contains(arr_video_azione[0]))
{
this.fade_mc(arr_video_loop[indice], arr_video_azione[0]);
}
else if(container_mc.contains(arr_video_azione[1]))
{
this.fade_mc(arr_video_loop[indice], arr_video_azione[1]);
}
else
{
this.fade_mc(arr_video_loop[indice], arr_video_loop[num]);
}
BO_mc.gotoAndPlay(2);
trace("nome video " + arr_video_loop[indice].vd.url + " " + arr_video_loop[indice].name)
}
private function noExit(e:KeyboardEvent):void
{
switch(e.charCode)
{
case Keyboard.ESCAPE:
e.preventDefault();
break;
default:
break;
}
} // private function noExit(e:KeyboardEvent)
/* onComplete function */
private function caricatiTutti(e:LoaderEvent):void
{
this.fade_mc(arr_video_loop[0]);
cam = Camera.getCamera();
//
if(cam)
{
cam.setMode(camW, camH, stage.frameRate);
teleCamera.attachCamera(cam);
_motionTracker = new MotionTracker(teleCamera);
//_motionTracker.flipInput = true;
_motionTracker.minArea = 80;
addEventListener(Event.ENTER_FRAME, onEnterFrameHandler);
this.addEventListener("azione", videoAzioneFunction);
}
else
{
telecamera_not_fount_timer.addEventListener(TimerEvent.TIMER, telecameraFunction);
telecamera_not_fount_timer.start();
}
} // private function caricatiTutti(e:LoaderEvent):void
private function telecameraFunction(e:TimerEvent):void
{
cam = Camera.getCamera();
//
if(cam)
{
telecamera_not_fount_timer.stop();
telecamera_not_fount_timer.reset();
cam.setMode(camW, camH, stage.frameRate);
teleCamera.attachCamera(cam);
_motionTracker = new MotionTracker(teleCamera);
//_motionTracker.flipInput = true;
_motionTracker.minArea = 80;
addEventListener(Event.ENTER_FRAME, onEnterFrameHandler);
this.addEventListener("azione", videoAzioneFunction);
}
}
private function caricaVideoLoop(e:LoaderEvent):void
{
mc = new MovieClip();
mc.addChild(e.target.content);
mc.vd = e.target;
mc.vd.addEventListener(VideoLoader.VIDEO_COMPLETE, videoLoopFunction);
mc.alpha = 0;
arr_video_loop.push(mc);
trace(mc.vd.name)
}
private function caricaVideoAzione(e:LoaderEvent):void
{
mc = new MovieClip();
mc.addChild(e.target.content);
mc.vd = e.target;
mc.alpha = 0;
mc.vd.addEventListener(VideoLoader.VIDEO_COMPLETE, videoLoopFunction);
arr_video_azione.push(mc);
trace(mc.vd.name)
}
/* fine onComplete function */
/* Fade */
private function fade_mc(mc_che_deve_entrare:MovieClip, mc_che_deve_uscire:MovieClip = null)
{
videoCorrente = mc_che_deve_entrare;
container_mc.addChild(mc_che_deve_entrare);
if(!impostazioniCaricati){
impostazioniCaricati = true;
this.dispatchEvent(new Event(Event.RENDER));
}
if(mc_che_deve_uscire)
{
mc_che_deve_uscire.vd.gotoVideoTime(0, false, false);
mc_che_deve_uscire.vd.videoPaused = true;
mc_che_deve_uscire.vd.volume = 0;
}
mc_che_deve_entrare.vd.gotoVideoTime(0, false, false);
mc_che_deve_entrare.vd.videoPaused= false;
if(standbyMode)
mc_che_deve_entrare.vd.volume = 0;
else
TweenMax.to(mc_che_deve_entrare.vd, 1, {volume:1});
if(mc_che_deve_uscire)
{
TweenMax.to(mc_che_deve_uscire, 1 ,{alpha:0, onComplete:eliminaIlMC, onCompleteParams:[mc_che_deve_uscire]});
}
TweenMax.to(mc_che_deve_entrare, 1 ,{alpha:1});
}
private function eliminaIlMC(e:MovieClip)
{
if(container_mc.contains(e))
{
trace("eliminato")
container_mc.removeChild(e);
}
}
private function eventRunningMode(e){
TweenMax.to(videoCorrente.vd, 1, {volume:1});
standbyMode = false;
trace("In running mode");
}
private function eventStandbyMode(e){
TweenMax.to(videoCorrente.vd, 1, {volume:0});
standbyMode = true;
trace("In standby mode");
}
private function eventSwitchingOn(e){
NativeApplication.nativeApplication.exit();
}
} // class
} // package
what can that be?