How to play part of an audio file on mouseclick or mouseover on a webpage?

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>

Answers


I would use a global variable to set the current stopping point and bind a timeupdate listener to check if the time has been reached:

var endTime = 0;
// do this binding once at page load time
myaudio.addEventListener("timeupdate", function() {
    if(this.currentTime >= endTime) {
        this.pause();
    }
});

With each event, set start time with myaudio.currentTime, the end time with endTime and the play() the audio:

// plays the audioObj from start to stop times (in seconds)
// call this for each snippet you wish to play (e.g., in an onclick handler)
function playInterval (audioObj, start, stop) {
    audioObj.currentTime = start*1000;
    endTime = stop*1000;
    audio.play();
}

Need Your Help

restkit.h file not found when archiving using xcode 6

ios restkit xcode6.3 archiving

i need your help everyone. i am having an error when archiving an app with restkit. On build it is perfectly ok, but when archiving it generates an error below:

Power Query - remove characters from number values

numbers character formula powerquery

I have a table field where the data contains our memberID numbers followed by character or character + number strings