Getting audio players to play their respective streams out of their element

What do I do next?

  function playButton(button) {
      var player = getAudio();
      var playing = isPlaying(button);
      showButton(button, playing);
      manageAudio(opts.playing, {
        playing
      });
  }

That function is trying to use opts, but it currently doesn’t exist as a function parameter.

Why isn’t the audio playing?

opts is broken - fix it.

How?

ReferenceError: opts is not defined

The playButton() function shouldn’t need to know about opts. Remove it.

What is the first parameter of the manageAudio() function?

Remove what??

      manageAudio(opts.playing, {
      });
  }

to:

      manageAudio(playing, {
      });
  }

one thing at a time.

Those are the arguments that you are passing to the manageAudio() function. They aren’t the parameters that the manageAudio() function accepts.

Now please find and identify what is the first parameter of the manageAudio() function.

You just told me to do this:

I didn’t do this yet.

The playButton() function shouldn’t need to know about opts. Remove it.

In order to fix the problem that you currently have there, you need to first understand what you must give as the first argument to the manageAudio() function.

Let me know when you want to understand that.

playing.

And that’s the only thing that should be in there.

Wrong. playing is not the first parameter that is accepted by the manageAudio() function.

    function manageAudio(player, opts) {
      if (opts.playing) {
        pauseAudio(player);
      } else {
        playAudio(opts.playing);
      }
    }

As you can see there, it is not playing that is accepted as the first parameter, but is player instead.

playing is a boolean value that can be a value of either true or false which indicates whether the button is currently playing or not.
player is a reference to the HTML audio player element.

Both are very different things.

1 Like

Still no audio:

You are still using opts in the playButton() function when you shouldn’t be.

What now?

Should I not be using opts in any of these either?

    function manageAudio(player, opts) {
      if (opts.playing) {
        pauseAudio(player);
      } else {
        playAudio(opts.playing);
      }
    }