想控制 html5 audio 声音到了指定时间暂停,帮忙看看下面的代码哪错了,在线等。
<!DOCTYPEHTML><html><body><script>varaudio;window.onload=function(){initAudio();}vari...
<!DOCTYPE HTML>
<html>
<body>
<script>
var audio ;
window.onload = function(){
initAudio();
}
var initAudio = function(){
audio = document.getElementById('audio');
}
function getCurrentTime(id){
alert(audio.currentTime + ':秒');
}
function playOrPaused(id,obj,srclj,kstime,jstime){
audio.src=srclj;
audio.currentTime=kstime;
audio.play();
stopOrPaused();
}
function stopOrPaused(){
Timess=audio.currentTime;
if(Timess > 1){
audio.pause();}else{
stopOrPaused();
}
}
</script>
<a href="javascript:void(0);" onclick="playOrPaused('firefox',this,'35.policeman.mp3',0,3);">播放</a>
<audio src="" id="audio" ></audio>
</body>
</html> 展开
<html>
<body>
<script>
var audio ;
window.onload = function(){
initAudio();
}
var initAudio = function(){
audio = document.getElementById('audio');
}
function getCurrentTime(id){
alert(audio.currentTime + ':秒');
}
function playOrPaused(id,obj,srclj,kstime,jstime){
audio.src=srclj;
audio.currentTime=kstime;
audio.play();
stopOrPaused();
}
function stopOrPaused(){
Timess=audio.currentTime;
if(Timess > 1){
audio.pause();}else{
stopOrPaused();
}
}
</script>
<a href="javascript:void(0);" onclick="playOrPaused('firefox',this,'35.policeman.mp3',0,3);">播放</a>
<audio src="" id="audio" ></audio>
</body>
</html> 展开
1个回答
展开全部
<!DOCTYPE HTML>
<html>
<meta charset=utf-8>
<title>audio</title>
<script>
var end = 3;
onload = function(){
audio.addEventListener('timeupdate', function () {
if(audio.currentTime>end){
audio.pause();
}
}, false);
audio.addEventListener('loadedmetadata', function () {
audio.play();
}, false);
}
</script>
<body>
<audio id="audio" src="htt防止和谐p://yinyueshiting.baidu.com/data2/music/37644759/734442924840032.m4a?xcode=5b7a4c9ffcee4c120c486914f0acd7b6" controls="controls">
Your browser does not support the audio element.
</audio>
</body>
</html>
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询