gpt4 book ai didi

javascript - HTML5音频标签停止按钮,是否停止直播MP3流?

转载 作者:行者123 更新时间:2023-12-03 02:19:48 25 4
gpt4 key购买 nike

我想添加一个停止按钮。目前只有一个播放和暂停按钮,但实际上并不是浏览器在缓冲音乐,而是不会跳到开头。使用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;
}
}

最佳答案

如果您只需要一个停止按钮,就不会通过javascript API直接控制此类事件。但是您基本上可以通过暂停歌曲并将其设置为从头开始播放来模拟相同的行为(前提是您不想停止缓冲)。像这样:

var stop = function(stopButtonAudio) {
stopButtonAudio.pause();
stopButtonAudio.currentTime=0;
}

关于javascript - HTML5音频标签停止按钮,是否停止直播MP3流?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15085320/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com