gpt4 book ai didi

javascript - 播放暂停按钮切换按钮

转载 作者:太空宇宙 更新时间:2023-11-04 00:56:53 26 4
gpt4 key购买 nike

请帮帮我,播放/暂停按钮到一个切换按钮意味着一次点击音频播放第二次点击然后音频暂停图标更改。提前致谢

.d-table {
display:table !important;
}

.d-table-cell {
display:table-cell !important;
}

.w-100 {
width: 100% !important;
}


.tar {
text-align: left !important;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<div class=" d-table w-100">
<p class="d-table-cell">بِسْمِ ٱللَّهِ ٱلرَّحْمَٰنِ ٱلرَّحِيمِ</p>
<div class="d-table-cell tar w-10">
<audio id="player2" src="http://www.mp3naat.com/download/owais-raza-qadri/mustafa-jaan-e-rehmat.mp3"></audio>
<a onclick="document.getElementById('player2').play()"><i class="fa fa-play-circle-o fa-2x"></i></a>
<a onclick="document.getElementById('player2').pause()"><i class="fa fa-pause-circle-o fa-2x"></i></a>
</div>
</div>

最佳答案

试试这个。它会在点击时切换以及播放和暂停

var play = false;
var audio=document.getElementById('player2');
function toggle() {
if (play) {
audio.pause()
} else {
audio.play();
}
};
audio.onplaying = function() {
play = true;
};
audio.onpause = function() {
play = false;
};
$(".w-10 >a> #a").click(function(){$(this).toggleClass("fa-play-circle-o fa-pause-circle-o")})
.d-table {
display:table !important;
}

.d-table-cell {
display:table-cell !important;
}

.w-100 {
width: 100% !important;
}


.tar {
text-align: left !important;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<div class=" d-table w-100">
<p class="d-table-cell">بِسْمِ ٱللَّهِ ٱلرَّحْمَٰنِ ٱلرَّحِيمِ</p>
<div class="d-table-cell tar w-10">
<audio id="player2" src="http://www.mp3naat.com/download/owais-raza-qadri/mustafa-jaan-e-rehmat.mp3"></audio>
<a onclick="toggle()"><i id="a" class="fa fa-play-circle-o fa-2x"></i></a>
</div>
</div>

关于javascript - 播放暂停按钮切换按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54472540/

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