简体   繁体   English

Soundcloud SDK-从URL加载轨道

[英]Soundcloud SDK - load track from url

So I did a tutorial on Soundcloud SDK through CodeAcademy here and wanted to take the knowledge I learned from that and put it on Codepen. 所以我在这里通过CodeAcademy在Soundcloud SDK上做了一个教程,想把从中学到的知识放到Codepen上。 But I want to use a different track than the one they use in this tutorial - specifically this song https://soundcloud.com/hardwell/coldplay-sky-full-of-stars-hardwell-remix-download . 但是我想使用与本教程中使用的曲目不同的曲目-特别是这首歌https://soundcloud.com/hardwell/coldplay-sky-full-of-stars-hardwell-remix-download

I read that /resolve was a good approach to get the trackid but it's not working. 我读到/resolve是获取trackid的好方法,但是它不起作用。 I get 403 Forbidden in the console. 我在控制台中看到403 Forbidden

SC.get('/resolve/?url=https://soundcloud.com/hardwell/coldplay-sky-full-of-stars-hardwell-remix-download&client_id=3596a42d6242b9c1ee76740a7771d33a', function(track) {
  console.log(track); // returns null
});

Here is my codepen . 这是我的codepen Please help me load this track for my basic SoundCloud SDK audio player. 请帮助我为我的基本SoundCloud SDK音频播放器加载此曲目。 Thanks 谢谢

Your code is correct and even works with some tracks, for example the ones from the documentation. 您的代码是正确的,甚至可以用于某些轨道,例如文档中的轨道。

You're encountering a problem that I found personally should be emphasized in their documentation. 您遇到的一个问题是我个人认为应该在他们的文档中强调。 The API access for this track has been disabled (even if the widget is enabled), therefore your have not right to query this track using the API and it returns a 403 Forbidden HTTP status code. 该轨道的API访问已被禁用(即使启用了小部件),因此您无权使用该API查询该轨道,并且它返回403 Forbidden HTTP状态代码。

This is described in the Linked Services part of the SoundCloud terms of use : SoundCloud使用条款的Linked Services部分中对此进行了描述:

You can limit and restrict the availability of certain of Your Content to other users of the Platform, and to users of Linked Services, at any time using the permissions tab in the track edit section for each sound you upload, subject to the provisions of the Disclaimer section below. 您可以随时针对上载的每种声音使用“曲目编辑”部分中的“权限”选项卡,来限制和限制某些内容对平台其他用户和链接服务用户的可用性。下面的免责声明部分。

You can check in your code if any error like this one was encountered while fetching the track informations and depending on the success or failure, continue with the correct action: 您可以在获取轨道信息时签入代码,是否遇到类似此错误的错误,并根据成功或失败而继续执行正确的操作:

var clientId = 'CLIENT_ID';

SC.initialize({
  client_id: clientId
});

var songUrl = 'https://soundcloud.com/hardwell/coldplay-sky-full-of-stars-hardwell-remix-download';

SC.get('/resolve?url=' + songUrl + '&client_id=' + clientId, function(data, error) {
  if (error === null) {
    console.log('Do something like playing the song.');
  } else {
    console.log('Print an error message?');
  }
});

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

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