I was experimenting with SoundCloud API in Elementor, but I couldn't solve a problem because I have very little knowledge about JS. I was trying to achieve custom play/stop button.
- I added a play icon, which changes to a stop icon
- It started playing as it should be, but now it's not stopping.
So when I click the icon with the id of #playBPP works well but when I click to the button again it's not working.
This is where I added JS.
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script>
<!-- SoundCloud-->
<script type="text/javascript" src="http://w.soundcloud.com/player/api.js"></script>
<script type="text/javascript">
// Play - Stop
$(function(){
var widget1 = SC.Widget("bppRadioPlayer");
$("#playBPP").click(function() {
widget1.play();
});
$("toggle-pause").click(function() {
widget1.pause();
});
});
// Audio button toggle
const audioButton = document.querySelector('.audio-button');
audioButton.addEventListener('click', function(){
audioButton.classList.toggle('toggle-pause');
});
</script>
<iframe id="bppRadioPlayer" width="100%" height="160" scrolling="no" src="http://w.soundcloud.com/player/?url=https://soundcloud.com/sdyld/bpp-bonvoyage" frameborder="0" ></iframe>
Icon HTML
<div class="elementor-element elementor-element-ff4607e audio-button elementor-view-default elementor-widget elementor-widget-icon" data-id="ff4607e" data-element_type="widget" id="playBPP" data-widget_type="icon.default">
<div class="elementor-widget-container">
<div class="elementor-icon-wrapper">
<div class="elementor-icon">
<i aria-hidden="true" class="fas fa-play"></i> </div>
</div>
</div>
</div>
.toggle-pause .elementor-icon i::before{
content: '\f04c';
}
I updated the snippet to achieve the goal, dropping here, so you can use.