Skip to main content
1-Visitor
December 16, 2019
Question

Linking Audio files to single Toggle Button

  • December 16, 2019
  • 1 reply
  • 2468 views

Hi Team, 

    Currently I'am trying to create an experience to demonstrate AR for service assembly wherein I have linked sequences of animation and bind them to a single toggle button using play binding feature. I have now imported multiple audio files and I'am trying to link those to a single toggle button, to which I have assigned animations using Play binding feature, so that with this toggle button I can play animation sequences with each click of toggle button.

I want to link multiple audio files so that with each click of the toggle button the animation and its respective audio plays. For eg; with individual click of toggle button animation for step 1 -  file of Audio 1 plays, with step 2 of animation Audio - file 2 plays, and so on.

1 reply

21-Topaz I
December 18, 2019

Hi @mady4383 ,

you can start a mp3 /needs to be a audio file  supported by the audio Widget/ by script.

e.g. define the following script in Home.js / or  respectively in <YourView>.js:

$scope.app.playAudio = function (mp3) {
 var audio = new Audio(mp3);
 audio.play();
}; 

$scope.toggleClick= function()
{
 
 console.log("toggleClick");
 
 $scope.app.playAudio('app/resources/Uploaded/background.mp3');

}

and call the toggleClick from the pressed event e.g.:

2019-12-18_8-48-41.gif

The audio file / here background.mp3  should be first uploaded to your resource folder

2019-12-18_8-52-37.gif

mady43831-VisitorAuthor
1-Visitor
December 19, 2019

Hi @RolandRaytchev,

     Thank you for your response, I tried to create the experience but I think I am missing some trick here, can you please explain me once more with the snaps which I have provided you. Suppose I am having multiple files similar to background1.mp3 and background2.mp3 which are present in Resource folder and I want it to assign these audio files to the toggle button as that created in the snap provided, what script I need to provide in the Home.js window. So that with first click of Toggle button my  background1.mp3 file plays and with the second click of Toggle button my  background2.mp3 file plays.

 

2019-12-18_8-52-37-1.gif

2019-12-18_8-48-41-1.gif

 

21-Topaz I
December 19, 2019

Hi @mady4383 ,

 

I did not test it yet , but I think this should work.

Let say you have a sequence with steps 1...10 and for each step you have it own audio step mp3 file let say  seq_audio_xx.mp3 where the xx belongs to the range 1...10  

So you can  modify the code by some think like this :

$scope.toggleClick= function()
{ 
 console.log("toggleClick");
 $scope.app.playAudio('app/resources/Uploaded/seq_audio_'+GetCurrentStep()+'.mp3');
}

 

where the implementation of GetCurrentStep could be something like:

 

GetCurrentStep = function () {
 
 return $scope.app.params.CURRENT_STEP;
}

with:

2019-12-19_13-24-24.gif

or :

GetCurrentStep = function () {
 return $scope.app.view.Home.wdg["model-1"].currentStep;
}