Question: 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.

Answer: 
Use some global variable and increment it whenever a function is called.

```
data = ['a','b','c']
flag = 0

function displayArray(){
    console.log(data[flag]);
    flag++;
}

displayArray()

```
You can do what you want in several ways:

### Use a global flag:

If what you need is a function that does something special *only* on the first run:

```
let didRun = false;
function SaveAndProceed() {
  if (!didRun) {
    // Code to run the first time
    console.log('running for the first time');
    didRun = true; // remember that the function ran
  } else {
    // Code for the second run and after
    console.log('running again');
  }
}

SaveAndProceed();
// logs 'running for the first time';
SaveAndProceed();
// logs 'running again';

```

> 
> Warning: [using globals is generally harmful](https://softwareengineering.stackexchange.com/questions/148108/why-is-global-state-so-evil)!
> 
> 
> 

### Higher order functions

In order to not use a global, and protect yourself from unexpected bugs, you can use a higher order function (a function that returns a function) to store the state internally:

```
function runner(firstTime, after) {
  let didRun = false;
  return function () {
    if (!didRun) {
      firstTime();
      didRun = true;
    } else {
      after();
    }
  }
}

const SaveAndProceed = runner(
  function firstTime() { 
    console.log('running for the first time'); 
  },
  function after() { 
    console.log('running again'); 
  }
);

SaveAndProceed();
// logs 'running for the first time';
SaveAndProceed();
// logs 'running again';

```

### Generators

Another option, if supported, is to use [generators](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator). Generators could be very useful, but may not be supported in the platform(s) that you need to support.

```
function* GenerateSaveAndUpdate() {
   console.log('running for the first time');
   yield firstInvocationResult;
   while(true) {
     yield nextInvocationsResult;
   }
}

const SaveAndProceed = GenerateSaveAndProceed();

SaveAndProceed.next();
// logs 'running for the first time';
SaveAndProceed.next();
// logs 'running again';

```