问题
I tried to use this snippet from the Soundcloud API:
<script src="http://connect.soundcloud.com/sdk.js">
<script>
SC.initialize({
client_id: 'YOUR_CLIENT_ID'
});
# stream track id 293
SC.stream("/tracks/293", function(sound){
sound.play();
});
</script>
It works in any browsers aside from Safari mobile, both on iPhone and iPad, where the music stream does not play at all.
What am I doing wrong? (I replaced track id and client id with my own details)
Thanks
回答1:
In mobile safari the play has the restriction that audio playback has to be triggered by a user action. So you'll have to add some sort of button or link which when clicked will call the sound.play() function.
回答2:
Here is work around for this issue. What you need to add extra html element.
<div class="player-helper"></div>
JavaScript
SC.stream('/tracks/' + id, {
useHTML5Audio: true,
debugMode: true
}, function(sound) {
let $eventEmitter = $('.player-helper');
$eventEmitter.on('click', function () {
sound.play();
});
$eventEmitter.trigger('click');
$eventEmitter.off('click');
});
来源:https://stackoverflow.com/questions/11103383/soundcloud-streaming-on-safari-mobile