Safari browser audio.play() is not working

Viewed 4144

I am using the following audio tag <audio id="player"></audio> and in jquery I have used
var player = document.getElementById('player'); player.src ='/ajax.php'; player.play();

Safari browser showing following error and audio is not playing. Unhandaled promise Rejection: NotSupportedError: The Operation is not supported

I have search this but not got any proper solution. Any one knows the solutions? Thanks in advance.

3 Answers

The browser had forbidden auto play, users have to click to play.

Please check the Mute settings.

  Unmute, if it is set to mute.
  https://support.apple.com/kb/PH21463?locale=en_US

The promise's rejection handler is called with an exception name passed in as its sole input parameter (as opposed to a traditional exception being thrown). Possible errors include:

NotAllowedError The user agent (browser) or operating system doesn't allow playback of media in the current context or situation. This may happen, for example, if the browser requires the user to explicitly start media playback by clicking a "play" button.

NotSupportedError The media source (which may be specified as a MediaStream, MediaSource, Blob, or File, for example) doesn't represent a supported media format.

Referenced from MDN website.

As you are getting the NotSupportedError error, Your should look for player.src ='/ajax.php'; here.

Related