Soundcloud / SoundManager2无法在Mobile上运行(IOS上的Safari / Chrome)

时间:2016-05-11 14:10:02

标签: javascript soundcloud soundmanager2

我有SoundCloud api加载曲目,然后通过SoundManager2播放它们。我在桌面上成功运行,但似乎无法在桌面上播放曲目。

我的代码在这里可用: http://codepen.io/chriswinch/pen/bpoWYr

HTML

<a class="button" href="#" data-sc-url="https://soundcloud.com/kiiaraonline/gold" data-playing="false">Play</a>

<a class="button" href="#" data-sc-url="https://soundcloud.com/rustie/first-mythz" data-playing="false">Play</a>

<a class="button" href="#" data-sc-url="https://soundcloud.com/rbstudiospar/virgo-vocup" data-playing="false">Play</a>

JS

var track_id,
    sound,
    sc_url,
    playing = false,
    button = $('.button'),
    client_id = "e2a6681bccff23130855618e14c481af";

SC.initialize({
  client_id: client_id
});

button.on('click', function() {
  if($(this).attr('data-playing') == "false") {
    button.attr('data-playing', "false");
    $(this).attr('data-playing', "true");

    sc_url = $(this).data('sc-url');    
    $.get('http://api.soundcloud.com/resolve.json?url='+ sc_url +'/tracks&client_id='+ client_id , function (data) {
      play_song(data);
    });

  } else {

    $(this).attr('data-playing', "false");
    stop_song();

  }
});

function play_song(data) {
  if(playing == true) {
    sound.stop();
  }
  track_id = data['id'];
  soundManager.setup({
    onready: function() {
      SC.stream('/tracks/' + track_id, {}, function(player) {
        sound = player;
        sound.play();
        playing = true;
      });
    }
  });
}

function stop_song() {
  console.log('stop song');
  sound.pause();
}

任何帮助将不胜感激。 干杯, 克里斯

0 个答案:

没有答案