2017-02-09 2 views
-2

자바 스크립트 코드 작성 방법을 모르겠으므로 음악 재생 및 정지 라디오 플레이어 토글 버튼을 만드는 데 어려움을 겪고 있습니다. 개발자가 서버에 Icecast를 설치했지만 불행히도 그는 매우 바쁩니다. 내가 가지고있는 것은 페이지가로드 될 때 자동으로 음악을 재생하는 HTML입니다.라디오 플레이어의 토글 시작/중지 버튼 만들기

많은 감사합니다.

<!DOCTYPE html> 
<html lang="en"> 
<head> 
<script src="http://radiocambodia.live/sound_manager/script/soundmanager2-jsmin.js"></script> 
<script src="http://radiocambodia.live/Helpers.js"></script> 
<script src="http://radiocambodia.live/WebRadio.js"></script> 
<script> 
     var stream_url = "http://radiocambodia.live:8000/stream.ogg"; 

     var radio = new WebRadio(stream_url); 

     radio.init({ 
      onloaded: function() { 
       console.log("Playing !"); 
       radio.soundObject.play(); 
      }, 

      onplaying: function() { 

      } 
     }); 

    </script> 
</head> 

<body> 
<a href="#"><img src="http://radiocambodia.live/pause.png" width="45" height="45" id="stopbutton" onclick='toggleSound()'; /></a> 
<script type="text/javascript"> 
function toggleSound() { 

    if (radio.soundObject.play){ 
document.getElementById('soundObject.stop').src='stop.png'; 
}else{ 
document.getElementById('soundObject.play').src='play.png'; 
} 

</script> 
</body> 
</html> 

답변

1

닫는 중괄호 누락 귀하의 toggleSound 기능, 여기에

<!DOCTYPE html> 
 
<html lang="en"> 
 
<head> 
 
</head> 
 

 
<body> 
 
<img id="togglePlay" src="http://radiocambodia.live/pause.png" width="45" height="45" id="stopbutton" onclick='toggleSound()'; /> 
 
<script src="http://radiocambodia.live/sound_manager/script/soundmanager2-jsmin.js"></script> 
 
<script src="http://radiocambodia.live/Helpers.js"></script> 
 
<script src="http://radiocambodia.live/WebRadio.js"></script> 
 

 
<script type="text/javascript"> 
 
    var stream_url = "http://radiocambodia.live:8000/stream.ogg"; 
 

 
    var radio = new WebRadio(stream_url); 
 

 
    radio.init({ 
 
     onloaded: function() { 
 
     console.log("Playing !"); 
 
     radio.soundObject.play(); 
 
    }, 
 

 
    onplaying: function() { 
 

 
    } 
 
    }); 
 
    function toggleSound() { 
 
     if (radio.soundObject.paused){ 
 
      radio.soundObject.play(); 
 
      document.getElementById('togglePlay').src='http://radiocambodia.live/pause.png'; 
 
     }else{ 
 
      radio.soundObject.pause();  
 
      document.getElementById('togglePlay').src='http://radiocambodia.live/play.png';   
 
     } 
 
    } 
 

 
</script> 
 
</body> 
 
</html>

radio.soundObject.paused 내가 전환하는 데 사용되는 이유는 부울 값을 반환하는 작업 솔루션은 다음과 같습니다 여기 코드는 재생과 일시 중지 사이. 어떤 API/라이브러리를 사용하든 더 잘 이해할 수있는 문서를 읽으십시오.

+0

많은 분들께 감사드립니다. azs06, 매우 쉽게 보이지만 코딩이 너무 어려워졌습니다! – snowblood

+0

사파리에서 작동하지 않는 이유를 알고 계십니까? ( – snowblood

+0

사파리에서 작동하지 않는 이유가 확실하지 않으므로 stream (http://radiocambodia.live:8000/stream.ogg)이로드되지 않는 것 같습니다. 사파리. – azs06

관련 문제