+ 12

How To Play And Pause Audio With Javascript Onclick event

26th May 2017, 2:21 PM
Kailash Loncha
Kailash Loncha - avatar
3 Réponses
+ 14
<button onclick= 'var a = document.getElementsByTagName("audio")[0]; if(a.paused)a.play();else a.pause()'>Play/Pause</button> <audio src="file:///sdcard/Sora-sound.mp3" ></audio> //Didn't test yet Pause audio element with .pause() play audio element with .play() //More: In The mobile browser. Audio is often played when onclick is fired
26th May 2017, 2:32 PM
Yanothai Chaitawat
Yanothai Chaitawat - avatar
+ 6
paused is property that return boolean. if audio is currently stop or not playing. This property return true .play() and .paused() are the function of audio element but checked....checked is attribute for <input> isn't it?
27th May 2017, 3:40 AM
Yanothai Chaitawat
Yanothai Chaitawat - avatar
+ 5
Ok Thanks
27th May 2017, 3:41 AM
Kailash Loncha
Kailash Loncha - avatar