How is SoundCloud Auto Playing the next song on their mobile site?

試著忘記壹切 提交于 2019-12-07 02:10:31

问题


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?


回答1:


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.




回答2:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!