SoundCloud阿比重定向混乱和音频阿比流 [英] SoundCloud Api redirect confusion and Audio Api Streams

查看:213
本文介绍了SoundCloud阿比重定向混乱和音频阿比流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图作出一个请求给SoundCloud的API。然后,当我得到的回应我设置stream_url作为一个&LT的来源; audio>元素。

本作品:

http://matthiasdv.org/beta/

但不总是这样。当你搜索倭比如,你可以玩的第几首曲目,没有任何问题。但是,当你尝试玩'伦敦语法 - 哎,现在(倭黑猩猩混音) - 第七届结果 - 它不会玩。这无论如何不引发错误。

我一直在摆弄周围的镀铬的Webdev的-工具和网络选项卡中我看到被提出的要求下。我发现,确实发挥轨道有一个简短的请求URL,像这样的:

<$p$p><$c$c>https://ec-media.sndcdn.com/vR5ukuOzyLbw.128.mp3?f10880d39085a94a0418a7ef69b03d522cd6dfee9399eeb9a522029f6bfab939b9ae57af14bba24e44e1542924c205ad28a52352010cd0e7dd461e9243ab54dc0f0bba897d

和那些不看是这样的:

<$p$p><$c$c>https://cf-media.sndcdn.com/8PCswwlkswOd.128.mp3?Policy=eyJTdGF0ZW1lbnQiOlt7IlJlc291cmNlIjoiKjovL2NmLW1lZGlhLnNuZGNkbi5jb20vOFBDc3d3bGtzd09kLjEyOC5tcDMiLCJDb25kaXRpb24iOnsiRGF0ZUxlc3NUaGFuIjp7IkFXUzpFcG9jaFRpbWUiOjE0MzM0Mjc2MDN9fX1dfQ__&Signature=cD-XVhnvQnIATkfrBDDVy0Q7996C8DymwxRLwBBduab0~L0MynF1ftcMky~21T8Q-gCZ2~dMK8dz7uVxvJTIJgXPxEZvhNtbvescMK6iFMg-xSAty-4OhJYjrIZJ2j8NE4uNA4Ml7MWbWcQw4KtUtpZitOQuguS3DPFDII3VF-dvzb2L~xG-G8Uu3uOnI1WhnAAfhf1QWMO7swwB89HtcCiuVBmfluG28ELrJEq-au8mqIMB3sLTno6nUuTtpHXR2ayXBsYcYLLJVXa3Ul8p1rhLS5XWHKWXY8xug4jwey27~C5PVAomK6Z5lJx-mz-0zYs4riUYtl0zACbZ1OfwTQ__&Key-Pair-Id=APKAJAGZ7VMH2PFPW6UQ

现在的第一眼我想这是一个编码的问题,而是包装快速连接codeURI()周围的AJAX网址没有工作。

此外,我不明白的地方,这些网址从何而来。在我的code我指挥我对Ajax请求,例如:

<$p$p><$c$c>https://api.soundcloud.com/tracks/140326936/stream?client_id=5c6ceaa17461a1c79d503b345a26a54e

因此​​,在GET请求的请求URL(在网络在Chrome的Webdev的工具中找到)是没有意义的我。难道SoundCloud重定向GET请求到CDN主机?还有一件事我注意到的是,每次两个请求被解雇,而不是一个。第一种是始终取消,并且包含一个'临时标头示警告。我相信这是因为我设置crossOrigin =匿名,否则某些浏览器将不会加载内容。

什么我估计可能导致的问题是,当链接被设定为evenListener烧制在dancer.js库中的元件,它处理音频API和播放( https://github.com/jsantell/dancer.js/ )。这可能是连接codeURI()的某处库要求。

我决定要问的问题,无论如何,因为我不明白是怎么URL请求的上方形成和为什么是两个,而不是一个,请求被解雇,为什么第一次总是取消。

这我解决播放问题的任何暗示都非常欢迎太...

解决方案

当您运行

请求

  https://api.soundcloud.com/tracks/140326936/stream?client_id=5c6ceaa17461a1c79d503b345a26a54e
 

您从服务器,这是一个URL重定向一个HTTP 302 Found响应(的http:// EN .wikipedia.org /维基/ HTTP_302 )。这将导致您的浏览器从这一新网址载入服务器返回的,这样的话你看这两个请求。服务器基本上说是的,我知道在哪里可以找到这个文件,请问那边那个人。

为什么一件作品和其他没有,我想原因是, https://开头EC-媒体.sndcdn.com 已成立,同时 https://cf-media.sndcdn.com的访问控制头的没有。这是一个问题的服务器配置,不幸的是什么,你可以从客户端控制。不知道如果这是一个深思熟虑的举动soundcloud或者如果它的东西,你可以问问他们。

I am attempting to make a request to the SoundCloud API. Then when I get the response I set the stream_url as the source of an < audio > element.

This works:

http://matthiasdv.org/beta/

But not always... When you search for 'Bonobo' for example, you can play the first few tracks without any issue. But when you try to play 'London Grammar - Hey Now (Bonobo remix)' - the 7th result - it won't play. It throws no errors whatsoever.

I've been tinkering around with Chrome's webdev-tools and under the network tab I see the requests being made. I found that tracks that DO play have a short Request Url, like this:

https://ec-media.sndcdn.com/vR5ukuOzyLbw.128.mp3?f10880d39085a94a0418a7ef69b03d522cd6dfee9399eeb9a522029f6bfab939b9ae57af14bba24e44e1542924c205ad28a52352010cd0e7dd461e9243ab54dc0f0bba897d

And the ones that don't look like this:

https://cf-media.sndcdn.com/8PCswwlkswOd.128.mp3?Policy=eyJTdGF0ZW1lbnQiOlt7IlJlc291cmNlIjoiKjovL2NmLW1lZGlhLnNuZGNkbi5jb20vOFBDc3d3bGtzd09kLjEyOC5tcDMiLCJDb25kaXRpb24iOnsiRGF0ZUxlc3NUaGFuIjp7IkFXUzpFcG9jaFRpbWUiOjE0MzM0Mjc2MDN9fX1dfQ__&Signature=cD-XVhnvQnIATkfrBDDVy0Q7996C8DymwxRLwBBduab0~L0MynF1ftcMky~21T8Q-gCZ2~dMK8dz7uVxvJTIJgXPxEZvhNtbvescMK6iFMg-xSAty-4OhJYjrIZJ2j8NE4uNA4Ml7MWbWcQw4KtUtpZitOQuguS3DPFDII3VF-dvzb2L~xG-G8Uu3uOnI1WhnAAfhf1QWMO7swwB89HtcCiuVBmfluG28ELrJEq-au8mqIMB3sLTno6nUuTtpHXR2ayXBsYcYLLJVXa3Ul8p1rhLS5XWHKWXY8xug4jwey27~C5PVAomK6Z5lJx-mz-0zYs4riUYtl0zACbZ1OfwTQ__&Key-Pair-Id=APKAJAGZ7VMH2PFPW6UQ

Now at first glance I figured it was an encoding issue, but wrapping a quick encodeURI() around the ajax url did not work.

Furthermore I do not understand where these urls come from. In my code I am directing my ajax request towards, for example:

https://api.soundcloud.com/tracks/140326936/stream?client_id=5c6ceaa17461a1c79d503b345a26a54e

Thus, the request url in the GET request (as found under 'network' in Chrome's webdev tools) makes no sense to me. Is SoundCloud redirecting get requests to a CDN-host? One more thing I've noticed is that each time TWO requests are fired instead of one. The first one is always canceled and contains a 'Provisional headers are shown' warning. I believe this is because I am setting crossOrigin = "anonymous", otherwise certain browsers would not load the content.

What I guess may cause the problem is that when the url is set as the src attribute of the element an evenListener is fired in the dancer.js library, which handles the Audio Api and the playback (https://github.com/jsantell/dancer.js/). It may be that encodeURI() is required somewhere in the library.

I decided to ask the question anyhow because I don't understand how the Request Urls's above are formed and why two, instead of one, requests are being fired and why the first is always cancelled.

Any hints which my solve the playback issue are more than welcome too...

解决方案

When you run the request for

 https://api.soundcloud.com/tracks/140326936/stream?client_id=5c6ceaa17461a1c79d503b345a26a54e

you get a HTTP 302 Found response from the server, which is a URL redirect (http://en.wikipedia.org/wiki/HTTP_302). This will cause your browser to load from the new URL that the server returns, and thus the two requests you see. The server basically says "yeah, I know where to find that file, ask that guy over there".

The reason why one works and the other not, I'd think, is that https://ec-media.sndcdn.com has the Access-Control headers set while https://cf-media.sndcdn.com doesn't. This is an issue with the server configuration and unfortunately nothing you can control from the client side. Dunno if it's a deliberate move by soundcloud or if it's something you could ask them about.

这篇关于SoundCloud阿比重定向混乱和音频阿比流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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