0

I try to play audio with javascript. I already found out how to do so in this thread:

var audio = new Audio('audio_file.mp3');
audio.play();

but there is no info on how to stop the audio again.

I tried audio.stop() but i get index.php:133 Uncaught TypeError: audio.stop is not a function I was wondering how i can find out all available methods from an object?

Community
  • 1
  • 1
Black
  • 15,426
  • 32
  • 140
  • 232

2 Answers2

2

One way is to use a for loop and log each key contained within the object to the console:

var audio = new Audio();

for (var key in audio)
  console.log(key)

If you want to specifically find functions, you can extend this to check implement a typeof check:

for (var key in audio)
  if (typeof audio[key] === "function")
    console.log(key)

var audio = new Audio();

for (var key in audio)
  if (typeof audio[key] === "function")
    document.write(key + "<br>")
James Donnelly
  • 122,518
  • 33
  • 200
  • 204
0

try audio.pause();

I found a list of methods for the audio object here: http://www.w3schools.com/jsref/dom_obj_audio.asp

Liam
  • 25,247
  • 27
  • 110
  • 174
gegillam
  • 126
  • 7
  • Whilst this is what OP should have used instead of `stop`, this doesn't answer the question that was asked. – James Donnelly Apr 08 '16 at 13:04
  • I found a list of methods for the audio object at w3schools. He asked how to find a list of methods for a javascript object. That is one simple way to do so. – gegillam Apr 08 '16 at 13:07