Question

Widget API Broken due to Chrome AutoPlay policy


@SoundCloudDev In your Widget API: SC.Widget.Events.READY is now broken due to Chrome's new AutoPlay policy. It is not possible to get the audio to autoplay anymore. Do you know a fix for this issue?

9 replies

I must preface this by explaining that the code execution starts from a click on a link, so Auto Play should work.

What I have found out so far, is that if the call to the:

```
player.bind(SC.Widget.Events.READY,function(){
onSCPlayerReady(player)
}
```

Is made from within an Ajax call, Chrome throws a warning about AudioContext & refuses to play the audio. It seems to be complaining about the fact that there is no user interaction. I think the event context is being lost inside the Ajax call.

When I make the call from a normal function, in other words, not inside an inner function, auto Play works fine. But, I have to make the call from within an Ajax request.

I have tried all the normal fixes like:

```
var that = this;
```

And:

```
$.ajax({
url: url,
context: this
})...
```

Please can someone help me, as this problem has seriously broken my audio application.

In Firefox, it works fine...
Userlevel 7
Badge +3
Hi there,

Hmm, it looks like this might be something only the end user has a say in. This article is addressing the topic on Chrome's end: https://developers.google.com/web/updates/2017/09/autoplay-policy-changes
The problem occurred because the Ajax called was wrapped inside:

jQuery(loading).fadeIn("slow",function(){
// Ajax code...
})

For some reason the event context gets lost and Chrome/SoundCloud throws a wobbly. This is some kind of obscure bug, that took me a week to resolve, by removing the code, line by line! The strange thing is, is that I don't even have an AudioContext set up in my code, so I have no idea why Chrome/SoundCloud were complaining about this!

Anyway, thanks for your help!
OK. I spoke too soon. Tonight, Google Chrome got updated automatically to the most recent version. After this, auto play stopped working again with a Google Audio Context policy warning. But, I have not set up an audio context. I am using the an iframe that is initiated on page load. I have created a play button that runs the code above. Fairly simple stuff.

Any ideas about how to resolve this problem. I am getting serously hacked off with Google.

The thing is, it works in every other browser including mobile Safari iOS 12.

Come on Google. Stop messing with our applications.
The Audio Context warning gets thrown just before I call:

player.play();

I was was thinking maybe I need to mute the audio?

When I muted my YouTube videos, they started playing automatically again????

I really think the SoundCloud technical team need to talk to Google about this and try to find some way that developers can enable auto play.
I will try the following tomorrow and let you know the results:

```
player.setVolume(0);
```

**Google's Auto Play policy explicitly states:**

Chrome's autoplay policies are simple:
  • Muted autoplay is always allowed
**Google's Auto Play policy goes on to state:**

Autoplay with sound is allowed if:
  • User has interacted with the domain (click, tap, etc.).
Now, each of my audio tracks has a big red play button next to it. When a user clicks on the button it uses an 'onClick' handler to send data through several functions, until it ends up firing the SoundCloud Widget API's:

```
player.bind(SC.Widget.Events.READY,function(){
player.play();
});
```

Now, it looks like I am adhering to Google's Auto Play policy, so why isn't it working?

And why on earth am I getting an 'Audio Context' warning in the console. I haven't set up an Audio Context, unless SoundCloud is creating one, behind the scenes.

If this is the case, the SoundCloud engineers need to to supply us with a hook, to interact with it. Then we can just add:

```
AudioContext.resume();
```
And why am I writing replies to myself?

This is is an important issue. It is affecting many developers globally. And, if SoundCloud fails to respond, many developers will start using alternative audio APIs. This is a competitive market place.

Please can someone at SoundCloud create a pull request to resolve some of the points above.
And I have just found out that:

```
player.isPaused();
```

Returns the player object itself and not a boolean as expected?

Has the SoundCloud Widget API been recently updated, because some strange things are happening now?

Reply