简体   繁体   中英

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 & 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>

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM