Pregunta

Trying to get an mp3 sound to play with a javascript class but not working. I am not familiar with javascript so I thought it would not be vary different from Java or C. however i do not know why this is not working. this is for an Android app that has built in wikitude. Wikitude uses javascript for adding any functionality to its use of the Android camera class.

trying to use the sound class and nothing i have tried seems to work.

http://www.wikitude.com/external/doc/alr/Sound.html

Here is the full code

<!DOCTYPE HTML>
<html>

 <head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<script>

var sound = new AR.Sound("assets/bell.mp3", {
 onLoaded : function(){sound.play();},
 onError : function(){

 },
});
AR.sound.onFinishedPlaying = function(){alert("Playing finished");};
AR.sound.load();
AR.sound.play();

</script>

<title></title>

<script src="architect://architect.js"></script>
<script type="text/javascript" src="../ade.js"></script>

<script src="js/marker.js"></script>
<script src="../ade.js"></script>

<link rel="stylesheet" href="css/default.css">
</head>

<body>
<script src="js/multiplepois.js"></script>

 </body>
 </html>
¿Fue útil?

Solución

You can't use something before it's defined, which in your case, is AR. Assuming AR is defined in your architect.js file, you need to move the inline script to somewhere after the library is loaded.

<script type="text/javascript" src="architect.js"></script>
<script type="text/javascript">
  var sound = new AR.Sound("assets/bell.mp3", {
    onLoaded : function() {
      sound.play();
    },
    onError : function() {}
  });

  AR.sound.onFinishedPlaying = function(){alert("Playing finished");};
  AR.sound.load();
  AR.sound.play();
</script>
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top