0

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 & 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>
Catcher
  • 55
  • 6

1 Answers1

0

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.

JAL
  • 41,701
  • 23
  • 172
  • 300
  • My use case does require user initiation, but that action calls play() from within stream(). Calling play() directly from the bound action instead works as expected. Thanks! – Catcher Jun 24 '15 at 16:56
  • With this being the case, what's the best way to wait until the stream action is done before attempting to play from the calling event? It seems callbacks are off limits to trigger the play action. – Catcher Jun 24 '15 at 17:23
  • The best solution I can find is to call a play & immediate pause in the event handler. This prevents the callback's play action from being disallowed. – Catcher Jun 24 '15 at 17:45