简体   繁体   English

JavaScript:流的简单SoundCloud API示例无法在Safari上正常使用

[英]JavaScript: Simple SoundCloud API example for Streaming won't work properly with Safari

I'm quite frustrated with a simple soundcloud api streaming example I'm working on for couple of days know. 几天来我一直在研究一个简单的soundcloud api流媒体示例,我对此感到非常沮丧。 It basically just chooses randomly a SC-url and prints out a volume information. 基本上,它只是随机选择一个SC网址并打印出卷信息。 I'm using the audiostreamsource.js library by Gregg Tavares for creating the audiocontext and the p5.js for creating a paragraph. 我正在使用Gregg Tavares的audiostreamsource.js库创建音频上下文,并使用p5.js创建段落。 That's it... It works perfectly fine on Fireforx/Chrome. 就是这样...在Fireforx / Chrome上可以正常工作。 But for some reason it only works in Safari when I refresh the page. 但是由于某种原因,当我刷新页面时,它只能在Safari中使用。 Sometime it even crashes with Safari. 有时它甚至在Safari中崩溃。 :( I think I'm just not experienced enough to get behind that problem. I really tried to solve it from every possible angle. Now I'm stuck.... :( :(我想我只是没有足够的经验来解决这个问题。我真的试图从各个角度解决这个问题。现在我被卡住了。...:(

You can see my little example here: http://christianlosert.com/test/01/ EDIT: To see the problem you have to past the link above into a new browser tab. 您可以在这里看到我的小示例: http : //christianlosert.com/test/01/编辑:要查看问题,您必须将上面的链接粘贴到新的浏览器选项卡中。 Then you'll see that after a couple of milliseconds the streaming aborts in Safari. 然后您会看到几毫秒后,流媒体在Safari中中止。

Can anybody see my mistake? 有人可以看到我的错误吗?

PS: With the help of Gregg Tavares I tried to create an streaming example without the audiostreamsource.js/p5.js library to make sure the bug is on my side of the code. PS:在Gregg Tavares的帮助下,我尝试创建一个没有audiostreamsource.js / p5.js库的流媒体示例,以确保该错误在代码方面。 Curiously this example works ONLY with Safari (not Firefox/Chrome): http://christianlosert.com/test/greg/ 奇怪的是,此示例仅适用于Safari(不适用于Firefox / Chrome): http : //christianlosert.com/test/greg/

I really have absolutely no clue what's going on here 我真的不知道这是怎么回事

The soundcloud 3.0 library does not work with Safari. soundcloud 3.0库不适用于Safari。 See 看到

soundcloud's 2.0 sdk works but 3.0 does not as of Oct 29th, 2015 截至2015年10月29日,soundcloud的2.0 sdk有效,但3.0无效

You can either 你可以

  1. use the soundcloud 2.0 library (problem: it initializes flash even if it doesn't use it) 使用soundcloud 2.0库(问题:即使不使用它也会初始化闪存)

  2. Just make the soundcloud API request on your own using some XHR code 只需使用一些XHR代码自行发出soundcloud API请求

    Basically you make an XHR request to 基本上,您向XHR请求

     https://api.soundcloud.com/resolve?url=<musicUrl>&client_id=<yourclientid>&format=json&_status_code[302]=200 

    note: you need to call encodeURIComponent on <musicUrl> and possibly on _staus_code[302] 注意:您需要在<musicUrl>以及可能在_staus_code[302]上调用encodeURIComponent

    If the result has a status of 302 then follow the location 如果结果的状态为302,则遵循位置

     var result = JSON.parse(resultString); if (result.status.substr(0, 3) === "302" && result.location) { do XHR on result.location else use result as normal 

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

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