现有一个mp3和lrc文件,如何读取lrc的时间标签,并根据间隔按照预设的模式进行播放呢?
比如先全文播放一遍,然后每个句子重复五遍,间隔10秒,最后全文再放一边。
假设lrc内容如下,用js控制全文播放一次,然后从开头播放到第1句,间隔指定的10秒,然后再重复4次,跳到第二句话,一直到最后一句话。最后再全文播放一次。
[00:00.37]第1句
[00:04.90]第2句
[00:09.65]第3句
[00:15.57]第4句
[00:22.15]第5句
[00:27.97]第6句
[00:30.50]第7句
[00:36.40]第8句
菜鸟太弱,写了个代码如下,只能运行一次,数据都是写死的。
<script>
var _end = 37; //需要停顿的秒数
var _pause=10;//需要停顿的时间
var _repeat=5;//重复的次数
var repeated=0;//控制重复的计数器
onload = function(){
audio.addEventListener('timeupdate', function () {
if(audio.currentTime>_end && repeated<=_repeat){
audio.pause();
document.getElementById("info").innerText="pause..."
repeated=repeated+1;
setTimeout(" document.getElementById('info').innerText='play...' + repeated;audio.currentTime=0;audio.play();//alert(audio.startTime);",_pause*1000);
}
}, false);
audio.addEventListener('loadedmetadata', function () {
audio.play();
}, false);
}
</script>
<body>
<audio id="audio" src="1.mp3" controls="controls">
Your browser does not support the audio element.
</audio>
<span id="info"></span>