현재 재생중인 mp3를 일시 중지하는 데 문제가 있습니다.JavaScript로 MP3 재생/일시 중지 문제
예를 들어,이 함수를 다음과 같이 실행하면 playSong(drake);
은 내 if 문의 첫 번째 부분에서 코드를 실행하기 시작하고 "drake"개체에서 MP3를 재생하고 songValue = 2를 설정합니다. 문제는 두 번째로 실행하면 노래를 일시 중지하지 않지만 내 console.log는 콘솔에 표시되므로 두 번째 부분을 클릭하면 두 번째 부분이 실행됩니다. 몇 가지 이유로 노래를 일시 중지하십시오.
//object with mp3 audio
var drake = {
value: 3,
name: 'Energy',
artist: 'Drake',
audio: 'energy.mp3', //
img: '<img style="width: 50%; margin-right: 25%; margin-left: 25%; margin-top: 10%;" src="http://www.getrichrapping.com/wp-content/uploads/2015/08/Drake-Energy.jpg">'
};
songValue = 1;
// plays and SHOULD pause a Song
function playSong(object) {
var Song = new Audio(object.audio);
//plays the song
if (songValue == 1) {
Song.play();
songValue = 2;
// SHOULD pause the song when the functions is runned the second time
} else if (songValue == 2) {
console.log("Is it working ?"); // String to test if the "else if" gets runned
Song.pause();
songValue = 1;
}
};
여기서 songValue가 정의되고 있습니까? object.value? –
오, 미안하지만 그것을 추가하는 것을 잊어 버렸습니다. 그냥 –