Home I can't restart my audio file
Reply: 0

I can't restart my audio file

user1363
1#
user1363 Published in June 18, 2018, 1:06 pm

I am trying to make a piano on my website and for some reason, whenever I click on a note twice, the second time always seems to continue on from the first time (assuming that I don't hold it for the full length of the audio file). How do I make it so that when I click on a note more than once, the audio file restarts every time (keep in mind that I'm new to JavaScript).

var C3 = new Audio();
C3.src = "assets/music/C3.mp3";
div.w{
	height: 282px;
	width: 59px;
    position: absolute;
	border-style:solid;
	border-width:3px;
}

div.b{
	height: 141px;
	width: 29.5px;
	position: absolute;
	background-color: #000000;
}
<div class="w" id="C3" type="button" 
onmousedown="C3.play();document.getElementById('C3').style.backgroundColor='#cecece'"
onmouseup="C3.pause();document.getElementById('C3').style.backgroundColor='#ffffff'" 
onmouseleave="C3.pause();document.getElementById('C3').style.backgroundColor='#ffffff'">
</div>

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.645313 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO