如何使用 SoundManager2 从 SoundCloud 流式传输,并进行可视化? [英] How to use SoundManager2 to stream from SoundCloud, and make visualizations?

查看:26
本文介绍了如何使用 SoundManager2 从 SoundCloud 流式传输,并进行可视化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SoundManager2 收到数据错误,我无法显示任何内容?

SoundManager2 gets a data error and I cannot visualize anything?

我无法访问歌曲,权限被拒绝?

I cannot access the song, permission denied?

我第一次玩的时候可以用,但是如果我暂停再玩,就会出现数据错误?

It works when I first play it, but if I pause it and play again, I get a data error?

推荐答案

最近已修复此问题,部分原因是所需文件中存在一半.现在它已修复,但它仍然可能无法立即工作.

This has recently been fixed, as it was partly due to half of the needed files being there. Now it is fixed however, it still might not work off the bat.

显而易见的第一步是您使用 api 获取轨道 stream_url,它看起来像 http://api.soundcloud.com/tracks/69322564/stream?client_id=CLIENT_ID

The obvious first step is you use the api to get the track stream_url, which looks like http://api.soundcloud.com/tracks/69322564/stream?client_id=CLIENT_ID

如果您将其用作 SoundCloud 中的媒体 url,您会发现您按下播放键,如果您有可视化效果,它们将起作用,一切都很好.但是,如果您现在暂停曲目并再次按下播放键,您将收到数据错误,元数据将不再可访问,您的可视化将中断.这是因为 api.soundcloud.com 有一个跨域文件,当你访问它时,你会得到一个 3XX 重定向到 ec-media.soundcloud.com.该站点现在也有一个 crossdomain.xml 文件,但是讨厌的 3XX 重定向破坏了这两个权限,因此您遇到了错误.

If you use this as the media url in SoundCloud, you will find that you press play, and if you have visualizations they will work, and everything is nice. However if you now pause the track, and press play again, you will get a data error, metadata will cease to be accessible, and your visualizations will break. This is because api.soundcloud.com has a crossdomain file, and when you access it you get a 3XX redirect to ec-media.soundcloud.com. This site now also has a crossdomain.xml file, however that pesky 3XX redirect ruins both permissions, so you hit an error.

这个问题的答案是你首先在 soundmanager2 之外进行重定向,这样就没有重定向会破坏它.例如在 Python 中:

The answer to this is you make the redirect leap first, outside of soundmanager2, so that there is no redirect that will break it. For instance in Python:

import urllib2
starturl = 'http://api.soundcloud.com/tracks/69322564/stream?client_id=CLIENT_ID'
res = urllib2.urlopen(starturl)
finalurl = res.geturl()
print finalurl

这可能更优雅,但它会打印 api 重定向到的 url.此网址类似于 http://ec-media.soundcloud.com/2j0lNF81jv9m.128.mp3?LONG_STRING&AWSAccessKeyId=ACCESS_KEY&Expires=1355864871&Signature=SIGNATURE

This could be more elegant, but it will print the url that the api redirects to. This url will look something like http://ec-media.soundcloud.com/2j0lNF81jv9m.128.mp3?LONG_STRING&AWSAccessKeyId=ACCESS_KEY&Expires=1355864871&Signature=SIGNATURE

这个域有crossdomain.xml文件,由于没有redirect,所以运行流畅,访问数据,一切顺利.

This domain has the crossdomain.xml file, and due to the fact that there is no redirect, things will run smoothly, data will be accessed, all will be well.

我做了这个并且它有效,但现在它说该文件被禁止"

"I did this and it worked, but now it says the file is forbidden"

现在我们提醒您注意之前的网址,特别是 &Expires=1355864871.您重定向到的文件不是永久性的,因此您每次都需要抓取它.对我来说这很容易,我在 django 中工作,所以我可以简单地在我的视图脚本中运行上面的 python.您必须找到一种方法来在您选择的代码中实现这一点.(也应该在 javascript 中工作).

Now we draw your attention to the previous url, in particular &Expires=1355864871. The file you are redirected to is not permanent, so you need to grab it each time. For me this is easy, I work in django so I can simply run the python above in my views scripts. You'll have to find a way to implement this in your code of choice. (Should work in javascript too).

完成所有这些后,您应该可以根据需要暂停和播放,并检索波形数据、均衡器数据和峰值数据.有了这些东西,就可以做一些有趣的事情了.希望这有帮助.

After all this is done, you should be able to pause and play as much as you want, and retrieve the waveform data, the EQ data, and the peak data. With these things, some fun things can be done. Hope this helped.

这篇关于如何使用 SoundManager2 从 SoundCloud 流式传输,并进行可视化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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