Start a new topic

Not able to stop the audio sound by using stop()

Not able to stop the audio sound by using stop()

1 person has this problem
1 Comment


Kindly find my code snippet

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();
Login or Signup to post a comment