没有发射的SoundCloud SDK / API回调事件 [英] SoundCloud SDK / API callback events not firing

查看:178
本文介绍了没有发射的SoundCloud SDK / API回调事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是一个简单的例子,我认为应该按照文档中工作。流上播放,但是回调不火。我是不是犯了一个错误,或者是有一个bug介于两者之间的SDK / API / SoundManager类?

Here's a simple example that I believe should be working per the docs. The stream plays, but the callbacks don't fire. Am I making a mistake, or is there a bug somewhere between the SDK / API / SoundManager?

<!DOCTYPE html>
<html>
<head lang="en">
  <meta charset="UTF-8">
  <title></title>
</head>
<body>
<h1>Sound Cloud API callback 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',
          {
              onload: function() { console.log("Does not fire."); },
              onplay: function() { console.log("Does not fire."); },
              onfinish: function() { console.log("Does not fire."); }
          },
          function(sound) { sound.play(); });
</script>
</body>
</html>

这是一个类似的问题,但没有出现过的答案。 <一href=\"http://stackoverflow.com/questions/31010292/soundcloud-javascript-sdk-2-0-stream-onfinish-event-does-not-execute/\">Soundcloud使用Javascript SDK 2.0 - 流onfinish事件不会执行

This is a similar question, but there have been no answers. Soundcloud Javascript SDK 2.0 - Stream onfinish event does not execute

推荐答案

在使用HTML5,可以直接针对音频元素并结合自定义操作,而不是在回调的事件。下面的例子是大致相当于未击发你的SDK事件。这是一种解决方法,但由于HTML5是默认方法,它的可靠共同使用包括iOS。

When using html5, you can target the audio element directly and bind custom actions to the callback events on that instead. The examples below are roughly equivalent to your SDK events that aren't firing. It's a workaround, but since html5 is the default method, it's reliable for common use including iOS.

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<h1>Sound Cloud API callback 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) {
                html5Audio = sound._player._html5Audio;
                html5Audio.addEventListener('canplay', function(){ console.log('event fired: canplay'); });
                html5Audio.addEventListener('play',    function(){ console.log('event fired: play'); });
                html5Audio.addEventListener('ended',   function(){ console.log('event fired: ended'); });
                sound.play();
            });
</script>
</body>
</html>

下面是更多的可用HTML5的媒体事件的列表:结果
https://developer.mozilla.org/en-US/docs /网络/指南/活动/ Media_events

Here's a list of more available html5 media events:
https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Media_events

这篇关于没有发射的SoundCloud SDK / API回调事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆