我是一名有用的助手,可以帮您进行翻译。以下是需要翻译的内容:
我有一个工作中的随机歌曲生成器,它有一个播放和暂停的按钮,以及一个随机歌曲的按钮。我是通过变量rand
和s
实现的,虽然这不是最好的方法,但它有效。当按下揭示按钮时,我希望能够揭示出这首歌曲,但我不知道如何去做,请问有人可以帮忙吗?
HTML:
<audio id="1st" >
<source src="intervals/1st.mp3" type = "audio/mp3"/>
</audio>
<audio id="2nd" >
<source src="intervals/2nd.mp3" type = "audio/mp3"/>
</audio>
<audio id="3rd">
<source src="intervals/3rd.mp3" type= "audio/mp3"/>
</audio>
<audio id="4th">
<source src="intervals/4th.mp3" type= "audio/mp3"/>
</audio>
<audio id="5th">
<source src="intervals/5th.mp3" type= "audio/mp3"/>
</audio>
<audio id="6th">
<source src="intervals/6th.mp3" type="audio/mp3" />
</audio>
<audio id="7th">
<source src="intervals/7th.mp3" type="audio/mp3" />
</audio>
<button type="button" id="reveal">Reveal</button>
<button type="button" id="playButton"></button>
<button type="button" id="randomise"></button>
JavaScript:
var playButtonJS = document.getElementById('playButton');
var randomiseJS = document.getElementById('randomise');
var revealJS = document.getElementById("reveal");
var FstJS = document.getElementById('1st');
var SndJS = document.getElementById('2nd');
var TrdJS = document.getElementById('3rd');
var FOthJS = document.getElementById('4th');
var FIthJS = document.getElementById('5th');
var SIthJS = document.getElementById('6th');
var SEthJS = document.getElementById('7th');
var audioPlaying = [FstJS, SndJS, TrdJS,FOthJS, FIthJS, SIthJS, SEthJS];
var rand = audioPlaying[Math.floor(Math.random() * audioPlaying.length)];
playButtonJS.addEventListener('click', playOrPause, false);
randomiseJS.addEventListener('click', random, false);
revealJS.addEventListener('click', rev, false);
function random() {
rand.pause();
playButtonJS.style.backgroundImage = 'url(playbutton.svg)';
var song = audioPlaying[Math.floor(Math.random() * audioPlaying.length)];
playButtonJS.style.backgroundImage = 'url(pausebutton.png)';
songf(song);
}
function songf(s) {
rand.currentTime=0;
rand = s;
if (!s.paused && !s.ended) {
s.pause();
playButtonJS.style.backgroundImage = 'url(playbutton.svg)';
}
else {
s.play();
playButtonJS.style.backgroundImage = 'url(pausebutton.png)';
}
}
function playOrPause() {
if (!rand.paused && !rand.ended) {
rand.pause();
playButtonJS.style.backgroundImage = 'url(playbutton.svg)';
}
else {
rand.play();
playButtonJS.style.backgroundImage = 'url(pausebutton.png)';
}
}