0
我想添加一個停止按鈕。此刻只有一個播放和暫停按鈕,但該停止並不是真正的瀏覽器緩衝音樂,但不會跳到開始。使用MP3文件也許是可以的,但不是在直播中。有人能幫我嗎?謝謝。HTML5音頻標籤停止按鈕,停止一個實時MP3流?
var pause = new Image();
pause.src = "pause.png";
var play_control = 0;
function playmusic() {
if (play_control == 0) {
document.getElementById('musikplayer').play();
document.getElementById('playbutt').src = 'pause.png';
play_control = 1;
window.setTimeout("playcontrol()", 0);
window.setTimeout("zeitanzeige()", 0);
} else {
document.getElementById('musikplayer').pause();
document.getElementById('playbutt').src = 'play.png';
play_control = 0;
}
}
function playcontrol() {
if(play_control == 1) {
if(
document.getElementById('musikplayer').currentTime
== document.getElementById('musikplayer').duration
) {
document.getElementById('playbutt').src = 'play.png';
play_control = 0;
} else {
window.setTimeout("playcontrol()",0);
}
}
}
function zeitanzeige() {
if(play_control == 1) {
var full = document.getElementById('musikplayer').duration;
var full_min = Math.floor(full/60);
var full_sec = Math.floor(full - (full_min * 60));
if(full_min < 10) {
full_min = '0' + full_min;
}
if(full_sec < 10) {
full_sec = '0' + full_sec;
}
var curr = document.getElementById('musikplayer').currentTime;
var curr_min = Math.floor(curr/60);
var curr_sec = Math.floor(curr - (curr_min * 60));
if(curr_min < 10) {
curr_min = '0' + curr_min;
}
if(curr_sec < 10) {
curr_sec = '0' + curr_sec;
}
document.getElementById('time').innerHTML = "" + curr_min + ":"
+ curr_sec + "";
window.setTimeout("zeitanzeige()",0);
} else {
document.getElementById('time').innerHTML = "00:00";
}
}
function vol(z) {
switch(z) {
case "1":
document.getElementById('musikplayer').volume = 0.2;
document.getElementById('vol1').style.background = '#c9c3c3';
document.getElementById('vol2').style.background = '#8d8585';
document.getElementById('vol3').style.background = '#8d8585';
document.getElementById('vol4').style.background = '#8d8585';
document.getElementById('vol5').style.background = '#8d8585';
break;
case "2":
document.getElementById('musikplayer').volume = 0.4;
document.getElementById('vol1').style.background = '#c9c3c3';
document.getElementById('vol2').style.background = '#c9c3c3';
document.getElementById('vol3').style.background = '#8d8585';
document.getElementById('vol4').style.background = '#8d8585';
document.getElementById('vol5').style.background = '#8d8585';
break;
case "3":
document.getElementById('musikplayer').volume = 0.6;
document.getElementById('vol1').style.background = '#c9c3c3';
document.getElementById('vol2').style.background = '#c9c3c3';
document.getElementById('vol3').style.background = '#c9c3c3';
document.getElementById('vol4').style.background = '#8d8585';
document.getElementById('vol5').style.background = '#8d8585';
break;
case "4":
document.getElementById('musikplayer').volume = 0.8;
document.getElementById('vol1').style.background = '#c9c3c3';
document.getElementById('vol2').style.background = '#c9c3c3';
document.getElementById('vol3').style.background = '#c9c3c3';
document.getElementById('vol4').style.background = '#c9c3c3';
document.getElementById('vol5').style.background = '#8d8585';
break;
case "5":
document.getElementById('musikplayer').volume = 1.0;
document.getElementById('vol1').style.background = '#c9c3c3';
document.getElementById('vol2').style.background = '#c9c3c3';
document.getElementById('vol3').style.background = '#c9c3c3';
document.getElementById('vol4').style.background = '#c9c3c3';
document.getElementById('vol5').style.background = '#c9c3c3';
break;
}
}
這是正確的嗎?它不工作:( – user2110505 2013-02-26 12:29:17
這是否正確實在不行 – user2110505 2013-02-26 12:33:05
VAR停止=功能(stopButtonAudio){ stopButtonAudio.pause();? stopButtonAudio.currentTime = 0; \t \t stop.src = 「stop.png」 ; } 功能stopButtonAudio(){ \t \t的document.getElementById( 'musikplayer')暫停(); \t \t的document.getElementById( 'stopbutt')SRC = 'stop.png'; – user2110505 2013-02-26 12:34:52