@
qianji201712 我帮你加了点功能,每次刷新页面会有不同的钢琴和不同的雨声搭配
<script>
const host = "
http://baidu.com/";
const rain = document.getElementById('player_rain');
const music = document.getElementById('player_music');
const playBtn = document.getElementById('btnPlay');
let platFirst = true;
var rainarray = ["rain/Birds_Early_Morning.mp3","rain/Rain_Totoro_ADForest.mp3","rain/SayamauMl_Rain_1.mp3","rain/therain.m4a","rain/Toropical_Rain.mp3"];
var musicarray = ["music/Across_the_Fields.mp3","music/EndIess_Pain.mp3","music/feng.mp3","music/In_Autumn_the_Leaves_Came_to_Our_House.mp3","music/yuzhou.mp3"];
function playAudio() {
if (rain.paused) {
if (platFirst) {
const sourceRain = document.getElementById("player_rain_source");
sourceRain.src = host + rainarray[Math.floor(Math.random()*5)];
setVolume(0.6, 1);
rain.load();
const sourceMusic = document.getElementById("player_music_source");
sourceMusic.src = host + musicarray[Math.floor(Math.random()*5)];
setVolume(0.5, 2);
music.load();
}
rain.play();
music.play();
playBtn.className = "";
playBtn.className = "pause";
} else {
rain.pause();
music.pause();
playBtn.className = "";
playBtn.className = "play";
}
platFirst = false;
}
function setVolume(volume, target) {
if (target === 1) {
rain.volume = volume;
} else {
music.volume = volume;
}
}
</script>