htmliossdksoundcloud

SoundCloud API stream on iOS / iPhone


Should the stream action via SC API / Javascript SDK 2.0.0 work on iOS/Safari? I'm finding that it doesn't with the trivial example below.

It seems like SoundManager is capable of knowing how and when to use html5. Am I mistaken?

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<h1>Sound Cloud iOS test</h1>
<script src="//connect.soundcloud.com/sdk-2.0.0.js"></script>
<script type="text/javascript">
    SC.initialize({
        client_id: "YOUR_CLIENT_ID"
    });

    SC.stream(
            '/tracks/293',
            function(sound) {
                sound.play()
            }
    );
</script>
</body>
</html>

Solution

  • You cannot force play or download any audio/video files in Safari on iOS devices without user initiation.

    In Safari on iOS (for all devices, including iPad), where the user may be on a cellular network and be charged per data unit, preload and autoplay are disabled. No data is loaded until the user initiates it. This means the JavaScript play() and load() methods are also inactive until the user initiates playback, unless the play() or load() method is triggered by user action. In other words, a user-initiated Play button works, but an onLoad="play()" event does not.

    This plays the movie: <input type="button" value="Play" onclick="document.myMovie.play()">

    This does nothing on iOS: <body onload="document.myMovie.play()">

    You will need to wrap your play action into a button, so that the audio stream is opt-in rather than automatic.

    Check this article in the Safari docs for reference.