1
I am developing a button to play audio in certain parts for my site, for example to have the narration of certain paragraph, I want to do this dynamically, for example by placing certain class and a date, it will search in the directory for the selected track.
I tried to make a code more or less with the idea that I have in mind of this function
function click(){
$('.audioplay').each(function(i){
var audioplay = new Audio('urldafaixa');
audioplay.preload = "auto";
$(this).click(function(e) {
e.preventDefault();
audioplay.currentTime = 0;
audioplay.play();
audioplay.volume = 1;
$(this).data("audio-click");
});
});
}
What’s the doubt? The error code? It doesn’t work as you expect?
– Neuber Oliveira
So it works, but every time I insert an audio I will have to create a different variable, for example audioplay2, 3 and so on, what I wanted was a way to insert several audios in different places of the page without having to replicate this function, so I thought I’d create a date, maybe make the date pick up the track url, but I’m not getting it done
– Thi100
@Thi100, you can use the attribute
data-
, as you quoted, as well as a array to store the Urls of audios.– Valdeir Psr
could show me an example ?
– Thi100
How do you access each url? This is in HTML? You can give an example of HTML?
– Sergio