Start a new topic

not able to stop audio sound using stop()

not able to stop audio sound using stop()


Kindly find my code sinppet

var World = {

loaded: false,

rotating: false,

 

init: function initFn() {

/* Disable all sensors in "IR-only" Worlds to save performance. If the property is set to true, any geo-related components (such as GeoObjects and ActionRanges) are active. If the property is set to false, any geo-related components will not be visible on the screen, and triggers will not fire.*/

AR.context.services.sensors = false;

this.createOverlays();

},

 

createOverlays: function createOverlaysFn() {

// Initialize Tracker

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

onLoaded: this.loadingStep

});

 

this.modelCar = new AR.Model("assets/car.wt3", {

onLoaded: this.loadingStep,

onClick: this.toggleAnimateModel,

scale: {

x: 0.0,

y: 0.0,

z: 0.0

},

translate: {

       x: 0.0,

y: 0.05,

z: 0.0

},

rotate: {

roll: -25

}

});

// instantiate the model object

//var model = new AR.Model("assets/boss.wt3");

 

// instantiate the model animation with the animation id

//var animation = new AR.ModelAnimation(model, "pPlane4_animation");

 

// start the animation

//animation.start();

 

// Appearing Animation

this.appearingAnimation = this.createAppearingAnimation(this.modelCar, 0.045);

 

// Rotation Animation

//this.rotationAnimation = new AR.PropertyAnimation(this.modelCar, "rotate.roll", -10, 335, 10000,{onStart : beepSound.play});

this.rotationAnimation = new AR.PropertyAnimation(this.modelCar, "rotate.roll", -25, 335, 10000);

 

var imgRotate = new AR.ImageResource("assets/rotateButton.png");

var buttonRotate = new AR.ImageDrawable(imgRotate, 0.2, {

offsetX: 0.25,

offsetY: 0.4,

onClick: this.toggleAnimateModel

});

 

var trackable = new AR.Trackable2DObject(this.tracker, "carAd", {

drawables: {

cam:

},

onEnterFieldOfVision: this.appear

});

},

 

loadingStep: function loadingStepFn() {

if (!World.loaded && World.tracker.isLoaded() && World.modelCar.isLoaded()) {

World.loaded = true;

var cssDivLeft = " style='display: table-cell;vertical-align: middle; text-align: right; width: 50%; padding-right: 15px;'";

var cssDivRight = " style='display: table-cell;vertical-align: middle; text-align: left;'";

document.getElementById('loadingMessage').innerHTML =

"<div" + cssDivLeft + ">Scan CarAd Tracker Image:</div>" +

"<div" + cssDivRight + "><img src='assets/car.png'></img></div>";

}

},

 

 

createAppearingAnimation: function createAppearingAnimationFn(model, scale) {

var sx = new AR.PropertyAnimation(model, "scale.x", 0, scale, 1500, {

type: AR.CONST.EASING_CURVE_TYPE.EASE_OUT_ELASTIC

});

var sy = new AR.PropertyAnimation(model, "scale.y", 0, scale, 1500, {

type: AR.CONST.EASING_CURVE_TYPE.EASE_OUT_ELASTIC

});

var sz = new AR.PropertyAnimation(model, "scale.z", 0, scale, 1500, {

type: AR.CONST.EASING_CURVE_TYPE.EASE_OUT_ELASTIC

});

 

return new AR.AnimationGroup(AR.CONST.ANIMATION_GROUP_TYPE.PARALLEL, );

},

 

appear: function appearFn() {

World.resetModel();

World.appearingAnimation.start();

},

 

resetModel: function resetModelFn() {

World.rotationAnimation.stop();

World.rotating = false;

World.modelCar.rotate.roll = -25;

},

 

toggleAnimateModel: function toggleAnimateModelFn() {

   var sound = new AR.Sound("assets/car-ignition-3.mp3");

if (!World.rotationAnimation.isRunning()) {

if (!World.rotating) {

World.rotationAnimation.start(-1);

World.rotating = true;

sound.play(); 

//alert("SOund played");

//sound.resume();

//alert("Sound Resume");

} else {

World.rotationAnimation.resume();

sound.stop();

 

}

} else {

World.rotationAnimation.pause();

sound.stop();

 

}

 

return false;

}

};

 

World.init();

 

 

 

Thanks in advance.

i m using Phonegap plugin.it starts playing the sound but dont stop

 

If any one have the Solution please provide it.

Thanks

From a quick look at it it seems you are creating a AR.Sound each time the toggle function is called. This means that by the time you call .stop() a new sound object has been created. Since you don't keep a reference to the original there is no way to call .stop on it.

I suggest to move the creation of the Sound object to createOverlays function.

I created AR.Sound object in createOverlays function and called sound.play() in toggle function

its giving error like 

03-28 09:57:15.902: E/Web Console(31492): Uncaught ReferenceError: sound is not defined at file:///android_asset/www/world/2_3dAndImageRecognition_3_Interactivity/js/imagerecognitionand3d.js:127

Kindly help

Thanks

Please use the ADE included with the SDK Package (ade.js) to run your world inside a desktop browser. This allwos you to debug such javascript errors more easily. My guess here is that 'sound' is declared with in the createOverlays function and therefore is not known in the toggleAnimateModel function. 

ADE is already included den also the toggle function is not geting the ar.sound object.Kinsly help me

Thank you

Did you run it inside a desktop browser and used the debugging tools available there to fix any javascript errors?

i tried running it inside a desktop browser but its just showing me main index.html page and on click of any sample its not opening the camera to scan the marker.Kindly help me

Thank you
 

The ADE is just a debugging environment for your javascript code. It allows to use all AR.xyz functions but does not render an AR scene. However there is a text based representation of all the objects you created and you have the possiblity to call triggers by clicking on an object's trigger function. To get to this text based representation click the triangle in the bottom right corner.
Login or Signup to post a comment