jQuery技术:如何在soundcloud javascript api中暂停流式传输

我想允许声音文件播放和暂停。 该文档显示了如何播放流文件:

$("#stream").live("click", function(){ SC.stream("/tracks/{'track-id'}", function(sound){ sound.play(); }; 

它使用Sound Manager来传输和使用它的一些对象和方法……比如.pause()!

所以这是我认为应该工作的代码:

  var is_playing="false"; $("#stream").live("click", function(){ SC.stream("/tracks/{'track-id'}", function(sound){ if (is_playing==="true") { sound.pause(); is_playing = "false"; console.log(is_playing); } else if (is_playing === "false") { sound.play(); is_playing = "true"; console.log(is_playing); } }); 

然而,它继续播放轨道而没有停顿。 有任何想法吗? 谢谢。

     var is_playing = false; soundManager.setup({ url: '/swf/soundmanager2.swf', preferFlash: false, onready: function() { var mySound = soundManager.createSound({ id: 'aSound', url: 'sonidos/sonido1.mp3' , autoplay: false }); $("#stream").live("click", function(){ if (is_playing==false){ mySound.play(); is_playing = true; }else if (is_playing== true) { mySound.stop(); is_playing = false; } }); }, /* ontimeout: function() { // Hrmm, SM2 could not start. Missing SWF? Flash blocked? Show an error, etc.? }*/ });  

    你必须使用sound.stop(); 还有一个内置function可以切换声音的播放/暂停。 使用sound.togglePause(); 要做到这一点。

     SC.stream("/tracks/13680213", function(sound) { SC.sound = sound; }); 

    这意味着您不是在SC.stream构造函数中编写事件侦听器,然后您可以随意访问以下(以及更多):

    SC.sound.play(); SC.sound.pause(); SC.sound.stop(); SC.sound.pause(); SC.sound.playState;

    由于关于这个问题的答案很少,我想我会回答我自己的问题。

    我继续下载Sound Manager 2并将必要的文件放在需要的位置(您可以在声音管理器2页面的基本教程部分找到它。)

    诀窍是找到与我想要嵌入的用户相关联的SoundCloud mp3。 为此,我必须使用RESTClient并输入相应的api url。 看起来像这样。

    {MyClient_ID_number}

    =“12758186”的通用指针。 接下来是JSONP包含我的个人client_id以validation我对soundcloud服务器的请求。

    一旦我有了这个url,我就在我的浏览器中尝试了它,并将其重定向到另一个url**,其中包含一个自动播放该歌曲的HTML5 mp3播放器。

    我从这个soundcloud doc获得了这个想法: http : //developers.soundcloud.com/docs#playing

    然后我复制了这个url并将我原来问题中的代码捣碎到上面提到的基本教程( )。

    最终守则:

      var is_playing = false; $("#stream").live("click", function(){ soundManager.setup({ url: './swf/soundmanager2.swf', onready: function() { var mySound = soundManager.createSound({ id: 'aSound', url: {**another url**}, autoplay: false }); if (is_playing===false) { mySound.play(); is_playing = true; } else if (is_playing=== true) { mySound.stop(); is_playing = false; } }, ontimeout: function() { // Hrmm, SM2 could not start. Missing SWF? Flash blocked? Show an error, etc.? } }); }); 

    只需将您想要触发暂停function的事件链接到传递给SC.stream()的回调函数的“声音”对象。

    以下代码中的表单接受声音云链接,例如: https : //soundcloud.com/djalmix-1/living-in-stereo-dj-almix (因此,一旦应用程序处于活动状态,请将其粘贴到表单中并单击加载)。 此外,您必须提供自己的client_id,soundcloud会在您注册应用时提供给您,这只需要一分钟左右。

    需要了解更多jQuery教程分享如何在soundcloud javascript api中暂停流式传输,都可以关注jQuery技术分享栏目—计算机技术网(www.ctvol.com)!

           

      以上就是jQuery教程分享如何在soundcloud javascript api中暂停流式传输相关内容,想了解更多jQuery开发(异常处理)及jQuery教程关注计算机技术网(www.ctvol.com)!)。

      本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

      ctvol管理联系方式QQ:251552304

      本文章地址:https://www.ctvol.com/jquerytutorial/982622.html

      (0)
      上一篇 2021年12月13日
      下一篇 2021年12月13日

      精彩推荐