Start a new topic

Onloaded (VideoDrawables) fires automatically!!!

Onloaded (VideoDrawables) fires automatically!!!


Hi Friends, I'm developing an app with many videos using a simple video sample and I implemented "Onloaded" event for video drawables and...oh! suprise! it fire automatically after the WORLD has been loaded, without I scan any target... I saw the data usage only open the app and wow! 30MB aprox downloaded.... 

Then.... what's the correct purpose of Onloaded Event??????

var Target_RECURSO10 = "TargetMotor2";

var media_video_RECURSO10 = "PapaNoel.mp4";

 

var World = {

loaded: false,

        interactionContainer: 'snapContainer',

init: function initFn() {

AR.context.services.sensors = false;

this.createOverlays();

},

 

createOverlays: function createOverlaysFn() {

// Initialize Tracker

this.tracker = new AR.Tracker("assets/TargetCollectionScanApp.wtc", {

onLoaded: this.worldLoaded

});

                

var video_RECURSO10 = new AR.VideoDrawable("assets/" + media_video_RECURSO10, 1, {

offsetY: 0,

                        offsetX: 0,

                        onError: function onErrorFn(){

                            alert("Error fire");

                        },

onLoaded: function videoLoaded() {

                            alert("OnLoaded fire");

                                 

}

});

                

this.AugmentReality_RECURSO10 = new AR.Trackable2DObject(this.tracker,Target_RECURSO10, {

drawables: {

                            cam:

},

onEnterFieldOfVision: function onEnterFieldOfVisionFn() {

                            World.video_RECURSO10.play(-1);

},

                        onExitFieldOfVision: function onExitFieldOfVisionFn(){

                            World.video_RECURSO10.stop();

                        }

});

                

        },

worldLoaded: function worldLoadedFn() {

 

        }

};

 

World.init();

Hi Pablo,
It might be that you didn't understand how your JS is evaluated. When your .html file is loaded, World.init() is called because it's in the global space. Inside World.init() you call createOverlays(). In createOverlays() you create a AR.VideoDrawable object which immediately starts loading it's content. That's why it appears to you that the video drawable fires onLoaded when the World loads. 
I attached a sample which creates the video drawable once you click a button in the .html file. onLoaded is then called after you clicked the button and the video drawable object was created.

I hope that helps you understand how your application works.

Best regards

Andreas

Hi Nicola, Yes... I know how it works, I understand that when the videodrawable is created, it downloads the video resource. In your example it depends of a button for create de videodrawable, but if I want 1000 videos it's imposible create 1000 buttons for me. My objective is that when a target is scanned, the video resource ito be downloaded, Is that posible?

 

        this.AugmentReality_RECURSO10 = new AR.Trackable2DObject( this.tracker, "*", {            

            onEnterFieldOfVision: function onEnterFieldOfVisionFn() {

                if ( World.video_RECURSO10 )

                {

               World.video_RECURSO10.play( -1 );

                }else{

                   //"create video drawable" <<<<<<<<<<<<<

                }

            },

            onExitFieldOfVision: function onExitFieldOfVisionFn() {

                if ( World.video_RECURSO10 )

                {

               World.video_RECURSO10.stop();

                }

            }

        } );

    },

 

Hi Pablo,
Yes it is ;)
I've updated the demo so that the video drawable is now created once a certain image target is recognized. I only moved the createVideoDrawable function call inside the onEnterFieldOfVision trigger:

onEnterFieldOfVision: function onEnterFieldOfVisionFn() {

                if ( !World.video_RECURSO10 )

                {

               // you could pass the name of the video depending of the trackable                

               World.createVideoDrawable();

                }

                

                World.video_RECURSO10.play( -1 );

            }

 

I hope you can finalize your implementation now.

 


Best regards

Andreas

Yes I've tried it... it's very fast and only there is streaming any resource in demand =)

Thank you so much
Login or Signup to post a comment