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


#1025

What do I do next?
https://jsfiddle.net/6ts492f6/477/

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

#1026

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


#1027

Why isn't the audio playing?
https://jsfiddle.net/6ts492f6/480/


#1028

opts is broken - fix it.


#1029

How?

ReferenceError: opts is not defined


#1030

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


#1031

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


#1032

Remove what??

      manageAudio(opts.playing, {
      });
  }

to:

      manageAudio(playing, {
      });
  }

#1033

one thing at a time.


#1034

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.


#1035

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.


#1036

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.


#1037

playing.

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


#1038

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


#1039

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

#1040

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.


#1041

Still no audio:
https://jsfiddle.net/6ts492f6/503/


#1042

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


#1043

What now?
https://jsfiddle.net/6ts492f6/509/


#1044

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

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