I am creating a website for teaching some arabic words. I am including numbers, ordinal numbers, days of the week etc. and I have a audio file that has them all and I would like to play it with mouseover or mouseclick. Now, I don’t want to have cut the audio into many pieces to make this work. Is there a way to call an audio file on mouseclick or mouseover and only play the file partially? For example I have an audio file that has numbers from 1 to 10 and let’s say each is a second long. When user click on number 5, I want to be able to call the numbers audio file and play the 5th second and stop. Is this possible? Following is my code that calls and plays the entire audio. Thank you!
<!DOCTYPE html>
<html>
<head>
<title>Arabic Letters</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<script language="javascript" type="text/javascript">
function playSound(soundfile) {
document.getElementById("dummy").innerHTML=
"<embed src=\""+soundfile+"\" hidden=\"true\" autostart=\"true\" loop=\"false\" />";
}
</script>
</head>
<body>
<span id="dummy"></span>
<a href="#" onclick="playSound('1-001_page3.mp3');"><p dir="rtl" lang="ar"
class="letter">واحِد</p></a>
</body>
</html>
I would use a global variable to set the current stopping point and bind a
timeupdatelistener to check if the time has been reached:With each event, set start time with
myaudio.currentTime, the end time withendTimeand theplay()the audio: