Here is a trick to overcome the limitations of modern mobile browsers which are o-so-reluctant to to unify their standards for the benefit of consumers and programmers. It appears that those browsers do not mind playing MP3 in video controls, so here you go:
function playVid() {
var myems = document.getElementsByTagName("em");
for (var i = 0; i < myems.length; i++) {
var myem = myems[i];
var myemid = myem.id;
myem.onclick = function () {
var video = document.getElementById('video1');
sndfile = this.id + ".mp3";
video1.src = sndfile;
video.load();
video.play();}
}
}
The function loops through EM element IDs and plays MP3 files in onclick event. Place this function in body onload event.
Place a video element somewhere in a tucked away location on your web page and set its width and height to 1px.
<video id="video1" width="1" height="1" > <source src=""/></video>
You can see this code in action on this interactive transcript page
No comments:
Post a Comment