Soundcloud Streaming on Safari Mobile

隐身守侯 提交于 2019-12-24 10:38:28

问题


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

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