Skip to main content
1-Visitor
February 12, 2020
Solved

Adding sound effect after I click a certain widget

  • February 12, 2020
  • 1 reply
  • 1148 views

Hi all,

I want to create a function that when a button is click a certain sound effect will appear. Is there a js code for this?

Best answer by Giuseppe_Fiore

use this Script, and associate this function to Click or another event of Widget.

 

$scope.mp3play=function() {

var audioElement;
if(!audioElement) {
audioElement = document.createElement('audio');
audioElement.innerHTML = '<source src="' + 'app/resources/Uploaded/File_Name.mp3'+ '" type="audio/mpeg" />'
}
audioElement.play();
};

 

File_Name.mp3 = name of file  saved into resource of project.

it has been tested and is working on  Tablet (Android & IOS) ,Mobile (Android & IOS), Hololens.

 

 

I HOPE TO HELP YOU

Giuseppe

1 reply

15-Moonstone
February 12, 2020

use this Script, and associate this function to Click or another event of Widget.

 

$scope.mp3play=function() {

var audioElement;
if(!audioElement) {
audioElement = document.createElement('audio');
audioElement.innerHTML = '<source src="' + 'app/resources/Uploaded/File_Name.mp3'+ '" type="audio/mpeg" />'
}
audioElement.play();
};

 

File_Name.mp3 = name of file  saved into resource of project.

it has been tested and is working on  Tablet (Android & IOS) ,Mobile (Android & IOS), Hololens.

 

 

I HOPE TO HELP YOU

Giuseppe