gpt4 book ai didi

javascript - 自定义 HTML5 Mp3 播放器

转载 作者:太空宇宙 更新时间:2023-11-04 16:05:41 24 4
gpt4 key购买 nike

我需要这个完整的功能,但我似乎忘记了如何将多个 JavaScript 文件连接到一个函数中。这是我的 Index.html

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript"
source src="/storage/
emulated/0/Documents/
Mp3Player/js/
MyScript.js"></script>
<script type="text/javascript"
source src="/storage/
emulated/0/Documents/
Mp3Player/js/MyScript1.js"></
script>
</head>
<body>
<img src="/storage/emulated/0/
Documents/Mp3Player/html/
images/play.jpg" width="200"
height="200" onclick="play();
changeImage();">
<audio id="audio" src="/storage/
emulated/0/Documents/
Mp3Player/html/music/
Rap_In_Darkness.mp3 "/>
</body>
</html>

这是用于音频播放的 MyScript.js。

function play(){ var myAudio = 
document.getElementById
("audio"); if(myAudio.paused)
myAudio.play(); else
myAudio.pause(); }

这是用于暂停/播放按钮图像的 MyScript1.js。

function changeImage() { if 
(document.getElementById
("imgClickAndChange").src == "/
storage/emulated/0/
Documents/Mp3Player/html/
images/Pause.jpg") {
document.getElementById
("imgClickAndChange").src = "/
storage/emulated/0/
Documents/Mp3Player/html/
images/play.jpg "; } else {
document.getElementById
("imgClickAndChange").src = "
storage/emulated/0/
Documents/Mp3Player/html/
images/Pause.jpg "; } }

最佳答案

像这样修改您的index.html

<!DOCTYPE html>
<head>
<script type="text/javascript"
src="/storage/
emulated/0/Documents/
Mp3Player/js/
MyScript.js"></script>
<script type="text/javascript"
src="/storage/
emulated/0/Documents/
Mp3Player/js/MyScript1.js"></
script>
</head>
<body>
<img src="/storage/emulated/0/
Documents/Mp3Player/html/
images/play.jpg" width="200"
height="200" onclick="play();
changeImage();">
<audio id="audio" src="/storage/
emulated/0/Documents/
Mp3Player/html/music/
Rap_In_Darkness.mp3 "/>
</body>
</html>

然后你的MyScript.js就像这样

function play(){ var myAudio = 
document.getElementById
("audio"); if(myAudio.paused)
myAudio.play(); else
myAudio.pause(); }

最后,你的 MyScript1.js 像这样

function changeImage() { if 
(document.getElementById
("imgClickAndChange").src == "/
storage/emulated/0/
Documents/Mp3Player/html/
images/Pause.jpg") {
document.getElementById
("imgClickAndChange").src = "/
storage/emulated/0/
Documents/Mp3Player/html/
images/play.jpg "; } else {
document.getElementById
("imgClickAndChange").src = "
storage/emulated/0/
Documents/Mp3Player/html/
images/Pause.jpg "; } }

关于javascript - 自定义 HTML5 Mp3 播放器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41905850/

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