Skip to content

Can't play sound in Safari OSX #27

Closed

Description

@patrickjuchli
SC.initialize({
    client_id: [CLIENT_ID]
});

SC.get("/resolve", { url: "https://soundcloud.com/roywoodsofficial/drama-feat-drake" }).then(t => {
    return SC.stream("/tracks/" + t.id);
}).then(sound => {
    sound.play();
});

Works in Chrome and Firefox, but Safari 9.0.1 on OSX and Safari on iOS 9.1 are showing the following error message:

[Error] Failed to load resource: Request header field Accept-Encoding is not allowed by Access-Control-Allow-Headers. (216772566.json, line 0)
[Error] XMLHttpRequest cannot load https://api.soundcloud.com/tracks/216772566.json?client_id=2e2d678be10b5a5d2d62af34b194428e. Request header field Accept-Encoding is not allowed by Access-Control-Allow-Headers.

Using the SDK at connect.soundcloud.com/sdk/sdk-3.0.0.js as well as soundcloud 3.0.1 on NPM.

Activity

  1. changed the title [-]Can't play sound in Safari OSX[/-] [+]Can't play sound in Safari OSX/iOS[/+] on Oct 29, 2015
  2. changed the title [-]Can't play sound in Safari OSX/iOS[/-] [+]Can't play sound in Safari OSX[/+] on Oct 29, 2015
  3. patrickjuchli commented on Oct 29, 2015

    @patrickjuchli
    Author

    The same example is working when using the SDK version 2 (without Promises of course).

  4. jv2222 commented on Nov 6, 2015

    @jv2222

    I got the same error. Any ideas on a workaround?

  5. thomasrhiel commented on Nov 11, 2015

    @thomasrhiel

    +1

  6. marlenesco commented on Nov 16, 2015

    @marlenesco

    +1

  7. soundreactor commented on Nov 29, 2015

    @soundreactor

    +1

  8. soundreactor commented on Nov 29, 2015

    @soundreactor

    this seems to be a server sided problem. in "Access-Control-Allow-Headers"
    Accept-Encoding is missing.

    workaround for me was to make a little php proxy and modify the soundcloud sdk 3.0.0:
    r = new XMLHttpRequest,
    r.open(t, 'https://mrvv.net/beta/proxy.php?url='+n, true), //make your own or use mine for the moment..

  9. Overload119 commented on Dec 7, 2015

    @Overload119

    +1

  10. andratwiro commented on Dec 23, 2015

    @andratwiro

    +1

  11. hiddebraun commented on Dec 30, 2015

    @hiddebraun

    +1

  12. ArthurRougier commented on Jan 30, 2016

    @ArthurRougier

    Any news on this one ? @janmonschke maybe ?

  13. heysamtexas commented on Feb 1, 2016

    @heysamtexas

    @soundreactor that is exactly what i did. :-)

  14. karensg commented on Feb 1, 2016

    @karensg

    I am just using the APIs without the Javascript SDK and I have the same bug. This is just a bug in Soundcloud API. How can it be that this bug is there for so long?

  15. lifter035 commented on Feb 2, 2016

    @lifter035

    @soundreactor what exactly did you do in your proxy.php? load url as file contents? could you share maybe?
    thanks

  16. 13 remaining items

  17. andrefelipe commented on Apr 30, 2016

    @andrefelipe

    +1

  18. auggod commented on Apr 30, 2016

    @auggod

    I just set up a gist with my personal solution for this (simple express server + nginx proxy) https://gist.github.com/auggod/019aa5eee8ef618dcf65678e4649d8a7

  19. vojkny commented on May 10, 2016

    @vojkny

    +1

  20. lukephills commented on May 23, 2016

    @lukephills

    The headers sent using 3.0 sdk sends

    http://api.soundcloud.com/resolve?url=someUrl&client_id=?????&format=json

    Where as the 2.0 sdk sends

    http://api.soundcloud.com/resolve?url=someUrl&client_id=?????&format=json&_status_code_map[302]=200

    Has anyone resolved this without proxying SC requests?

  21. dy commented on Jun 6, 2016

    @dy

    Oh, I was thinking something is wrong with xhr in safari.
    @lukephills thanks for 2.0 sdk url. At least some backend-less workaround.

  22. diurnalist commented on Jun 9, 2016

    @diurnalist
    Contributor

    👋

    I took some time to investigate and fix this today. It will be published in version 3.1.2 of the SDK to both NPM and our connect.soundcloud.com asset hosting domain. I need to work with some others to make sure it goes live.

    See #63 for the fix. If anybody has found an official bug report for this behavior in Safari, I'd love to see it. It is a bizarre behavior by the browser, but I wasn't able to find proof of it being recognized as a bug.

  23. diurnalist commented on Jun 9, 2016

    @diurnalist
    Contributor

    Published as https://connect.soundcloud.com/sdk/sdk-3.1.2.js - I hope this fixes things for you all ❤️

  24. andrefelipe commented on Jun 9, 2016

    @andrefelipe

    Works for me! https://www.anzuclub.com

    Thanks!

  25. jv2222 commented on Jun 9, 2016

    @jv2222

    Doesn't work for me. Same issue as before. You can see here...

    http://techzinglive.com/page/1584/296-tz-discussion-in-the-ether

    View in chrome and the player works and view in safari and it doesn't with the following error:

    Failed to load resource: Request header field Accept-Encoding is not allowed by Access-Control-Allow-Headers.
    
    XMLHttpRequest cannot load https://api.soundcloud.com/tracks/266282700?client_id=4949f9f85ff88c4a4d644266e3037754. Request header field Accept-Encoding is not allowed by Access-Control-Allow-Headers.
    
  26. diurnalist commented on Jun 10, 2016

    @diurnalist
    Contributor

    @jv2222 The reason is that the code on that page does the following:

    SC.get('/resolve?url=https://soundcloud.com/techzing/techzing-296')
      .then(function (track) {...})

    You should instead change this to:

    SC.resolve('https://soundcloud.com/techzing/techzing-296')
      .then(function (track) {...})

    The former example works on Chrome/Firefox because the SDK will transparently follow redirects when present. The /resolve endpoint performs a 302 redirect to a different API url. However, as we've seen with Safari, that doesn't work very well due to some strange CORS behavior. If you use the official SC.resolve function, it has a workaround in place to solve this problem.

    I'm not aware of any other SoundCloud API endpoints that need redirects to function, so if you just change that one piece, it should start working. Hope that helps.

  27. lukephills commented on Jun 16, 2016

    @lukephills

    Hi @diurnalist, thanks for working on this issue, although the problem still occurs for me.
    Loading a track from the SC API into web audio XHR still throws these errors:

    [Log] Loading track: https://api.soundcloud.com/tracks/267123288/stream?client_id=7258ff07f16ddd167b55b8f9b9a3ed33 (SoundCloudAPI.js, line 58)
    [Error] Failed to load resource: the server responded with a status of 403 (Forbidden) (TBBAwaj0kXXn.128.mp3, line 0)
    [Error] Failed to load resource: Request header field Accept-Encoding is not allowed by Access-Control-Allow-Headers. (TBBAwaj0kXXn.128.mp3, line 0)
    [Error] XMLHttpRequest cannot load https://cf-media.sndcdn.com/TBBAwaj0kXXn.128.mp3?Policy=eyJTdGF0ZW1lbnQiOlt7IlJlc291cmNlIjoiKjovL2NmLW1lZGlhLnNuZGNkbi5jb20vVEJCQXdhajBrWFhuLjEyOC5tcDMiLCJDb25kaXRpb24iOnsiRGF0ZUxlc3NUaGFuIjp7IkFXUzpFcG9jaFRpbWUiOjE0NjYwNDQyNzN9fX1dfQ__&Signature=vsUqIxWcwg~zVpAdYXswMPGl9degUBP4bRm~fKdd05zH0cIhENm~VkTzgSwtXCiAEtZ-aOOHgDPlGIRjHwOnF0vfo2KYVS5jcMdGy6PpLx9ac9U026ZadeBk791UO~5mgx9hLWHj4U9GuJ5x-7FeoPCSu4wCbs97bB1O6aFGeCLAk6bWyZqbNxHbFQY7D5olyGkRSCl7xRxIHhKDlN2EdXKmWBx69KltyYU1-nyngPiHD2TZgTU7JHYDQTZEccydYcA5Ph8U~1advoVseptLE18SQ7xwH1nFW75FOiKiDbAkkNEdKmNDGETdlBsJL-sxL6ELHh6P7XCHbp2o1OMEyw__&Key-Pair-Id=APKAJAGZ7VMH2PFPW6UQ. Request header field Accept-Encoding is not allowed by Access-Control-Allow-Headers.
    
  28. jv2222 commented on Jun 17, 2016

    @jv2222

    @diurnalist Dude, thanks, you nailed it!

  29. diurnalist commented on Jun 17, 2016

    @diurnalist
    Contributor

    @lukephills without more information, such as a reproduction link, I'm afraid I can't diagnose any further. Can you open a new issue if and when you have more info? I'm going to lock this issue for now.

  30. locked and limited conversation to collaborators on Jun 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions