简体   繁体   English

SoundCloud API流媒体错误

[英]SoundCloud API streaming bug

I'm using the SoundCloud API to stream songs but am experiencing the following (what I think is a) bug. 我正在使用SoundCloud API来播放歌曲,但是遇到以下(我认为是)错误。

When clicking a button the track is streamed and played, when I click another, the playback gets paused. 单击一个按钮时,将播放并播放曲目,当我单击另一个按钮时,播放会暂停。 This is basically done with this piece of code: 这基本上是用这段代码完成的:

var playerVar;
SC.initialize({ client_id: 'sorryCantPublishThat' });

$('#play').click(function(){
  SC.stream('/tracks/' + trackID ).then(function(player){
    player.play();
    playerVar = player;
  });
});

$('#pause').click(function(){
  playerVar.pause();
});

This works fine, as long as i don't click play again, after pausing the stream. 只要暂停流后,我不再次单击播放,此方法就可以正常工作。 Because then it plays, but I cannot stop the stream. 因为那样会播放,但是我无法停止播放。 I have to click the play button once again, then I can stop it. 我必须再次单击播放按钮,然后才能停止它。

Any ideas if I'm doing something wrong or if it's a bug? 如果我做错了什么或者是错误,有任何想法吗? Any besides that, how can I get this working correctly? 除此之外,我该如何正常工作?

I think I found out how to get this working. 我想我已经找到了如何使它工作的方法。 I now stream all the tracks as soon as the page gets loaded, and not only when the play button is clicked. 现在,我会在页面加载后立即播放所有曲目,而不仅仅是单击播放按钮时。 Every track has it's own variable: 每个轨道都有其自己的变量:

SC.initialize({ client_id: '' });

SC.stream('/tracks/' + track.id ).then(function(player){

    player.on('time', function () {
        // update 
    });

    soundCloudPlayers[ track.id ] = player;

});

And then, when the play button is clicked: 然后,当单击播放按钮时:

$('.play').click(function() {

    var player = soundCloudPlayers[ $(this).attr('data-trackid') ];
    player.play();

    player.on('time', function () {
        // update the current playback position indicator
    });
});

So this is also the place where the event listeners are placed. 因此,这也是放置事件侦听器的地方。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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