I have soundcloud embedded in my post as
<iframe class="soundcloud_iframe" width="100%" height="166" scrolling="no" frameborder="no" src="'.esc_url('https://w.soundcloud.com/player/?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F'.$custom['soundcloud'][0].'').'"></iframe>
Where $custom['soundcloud'][0]
is a post custom type that I can put in my post, and it's the id of the song on soundcloud.
I have also covered my soundcloud iframe which loads the default player, with a 'cover_over_soundcloud' absolutely positioned div that has a 'play button' on it.
So when you click it, the iframe should begin playing.
var $soundcloud_iframe = $('.soundcloud_iframe');
if ($('.cover_over_soundcloud').length) {
$('.play_button').on('click', function() {
$(this).parent().fadeOut();
$soundcloud_iframe.play();
});
}
.cover_over_soundcloud {
position: absolute;
min-height: 200px;
width: 100%;
background: #fdfdfd;
top: 0;
left: 0;
right: 0;
}
.cover_over_soundcloud .play_button {
position: absolute;
border: 3px solid #272727;
border-radius: 50%;
width: 50px;
height: 50px;
top: 75px;
left: 50%;
margin-left: -25px;
text-align: center;
line-height: 50px;
cursor: pointer;
}
.cover_over_soundcloud .play_button:after {
content: "";
position: absolute;
top: 30%;
left: 43%;
border-left: 10px solid #272727;
border-top: 10px solid transparent;
border-bottom: 10px solid transparent;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="cover_over_soundcloud">
<div class="play_button"></div>
</div>
<iframe class="soundcloud_iframe" width="100%" height="166" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F192479201"></iframe>
Now, since I'm not using soundcloud API, I cannot use the official soundcloud widget methods, especially .play()
which is what I'd need.
Is there a workaround for this?
It's kinda silly to have to click on a play button only to have to click again on the soundcloud play button.
I'm hiding it, because it doesn't look nice on my site as is, so this is a way to go around it.