why doesn't Chrome stream a song using SoundCloud API V3

一曲冷凌霜 提交于 2019-12-11 02:08:08

问题


I am trying to stream a song using SoundCloud api, but apprantly it does not play it in Chrome. However it works on other browsers.

SC.initialize({
  client_id: '65243ec784b284f1d8a8f950312240fa',
  redirect_uri: 'http://example.com/callback'
});

SC.stream('/tracks/293').then(function(player) {
  player.play();
});

JSFIDDLE

Any idea to make it working in Chrome?


回答1:


see my solution on the open Github issue (code pasted below for convenience).

If you use SoundManager2, then call setup when the dom is ready.

Rather than using the stream function of the SoundCloud api, call SC.get and then create a soundobject in SoundManager using createSound(), passing in the stream_url from the track that you just grabbed.

SC.get('/users/711016/tracks').then(function(tracks) {
    var sound = soundManager.createSound({
        id: 'mySound',
        url: tracks[0].stream_url + "?client_id=YOUR_CLIENT_ID",
        stream: true
    });
    sound.play();
});

I imagine the api route to the track(s) you are trying to play may be different than mine.




回答2:


This is a known compatibility issue due to Chrome's version of Flash. There is little you can do besides disable Flash or play with the different versions of the SDK to see which one works for your specific build of Chrome.




回答3:


As JAL said, this is unfortunately known and there doesn't seem to be a fix out there.

Instead what I would suggest doing is using their widget API to create a custom iFrame (you can make it invisible if you want), and then use the .load() method to load whichever track, or tracks you want. You can read about that here.

The widget API is really nice because it comes with a bunch of event listeners that are very helpful, depending on what you're doing.



来源:https://stackoverflow.com/questions/35631333/why-doesnt-chrome-stream-a-song-using-soundcloud-api-v3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!