Skip to content

Instantly share code, notes, and snippets.

@edmeehan
Created August 30, 2019 04:18
Show Gist options
  • Select an option

  • Save edmeehan/41097d5d070fd33017996cf8b9c253ea to your computer and use it in GitHub Desktop.

Select an option

Save edmeehan/41097d5d070fd33017996cf8b9c253ea to your computer and use it in GitHub Desktop.
Auto play next sound cloud widget
(function(SC){
const scIframes = [...document.querySelectorAll('iframe[src*="soundcloud.com/player"]')],
soundFinished = function(sc){
const index = scIframes.findIndex((item) => item === this);
if(index < scIframes.length) scWidgets[index + 1].play();
};
let scWidgets = scIframes.map((item) => {
const widget = SC.Widget(item);
widget.bind(SC.Widget.Events.FINISH, soundFinished.bind(item));
return widget;
});
})(SC);
@edmeehan
Copy link
Author

Page requires SoundCloud API script - https://w.soundcloud.com/player/api.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment