Okay, so I know that iOS doesn't allow auto-play, but how is SoundCloud auto-playing the next song on their mobile site?
I can get the next song I want to fill in the iframe src and the widget reloads to display that track.
I have tried many workarounds, even if I call the 'sc.play()' method when the next track is ready I still can't get it to auto-play. The big orange button on the iframe changes to the pause button, but it just won't play. I have to hit the button again to get playback to start.
Having the user initiate the first play is fine, but how is SC auto-playing the next track?
take a look at Controlling Media with JavaScript at Apple's website, in the Listing 4-4 Replacing media sequentially, you will find the following sample code:
<!doctype html>
<html>
<head>
<title>Sequential Movies</title>
<script type="text/javascript">
// listener function changes src
function myNewSrc() {
var myVideo = document.getElementsByTagName('video')[0];
myVideo.src = "http://homepage.mac.com/qt4web/myMovie.m4v";
myVideo.load();
myVideo.play();
}
// add a listener function to the ended event
function myAddListener(){
var myVideo = document.getElementsByTagName('video')[0];
myVideo.addEventListener('ended', myNewSrc, false);
}
</script>
</head>
<body onload="myAddListener()">
<video controls
src="http://homepage.mac.com/qt4web/A-chord.m4v">
</video>
</body>
</html>
the video does not work, but i think you can easily change it to what you want.
i have worked on soundcloud API , so i know this. When you search for particular song then in response it gives many song url (buffering URL), so simply they are putting all the url in the queue. So as soon as one song completes next starts.
来源:https://stackoverflow.com/questions/34330797/how-is-soundcloud-auto-playing-the-next-song-on-their-mobile-site