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


#885

What place is it supposed to be in?


#886

The manageAudio() function still has four parameters to it. Replace it with the updated function from post #869


#887

I did and it doesn't work.


#888

Then do it again, for only a tiny tweak is required to get it going.


#889

Broken
https://jsfiddle.net/6ts492f6/352/


#890

I don't recall ever instructing you to put a semicolon on the function declaration line.

  function manageAudio(player, {src, playing, audioDelay}); {

#891

Here:
https://jsfiddle.net/6ts492f6/354/

no audio.


#892

Here:
https://jsfiddle.net/6ts492f6/357/


#893

You still aren't using the correct code for that function, which is from post #869

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

#894

And the correct code to call that function, is given in post #871 which is:

manageAudio(player, {
  src: button.getAttribute("data-audio"),
  playing,
  audioDelay
});

#895

Audio is not playing:
https://jsfiddle.net/6ts492f6/364/


#896

You're confusing me.

Am I using this:

manageAudio(player, {
  src: button.getAttribute("data-audio"),
  playing,
  audioDelay
});

or

this:

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

#897

You are to use both. The second one is the function declaration, and the first one calls the second one giving it the options that it needs.


#898

The first piece of code that you most recently posted, belongs in the playButton() function, replacing the existing manageAudio line that's in there.


#899

This:
https://jsfiddle.net/6ts492f6/371/


#900

Tidy the code and it'll be all good.


#901

I can delete this then?
var src = button.getAttribute("data-audio");
https://jsfiddle.net/6ts492f6/376/


#902

Yes, that was there only until we had a better way of doing it, which is happening now.


#903

If I were top use this instead of src:
player.setAttribute("src", "http://hi5.1980s.fm/;");

https://jsfiddle.net/6ts492f6/332/

Would I be able to set this up like this?

  function manageAudio(player, playing, audioDelay) {
    if (playing) {
      pauseAudio(player);
    } else {
      delay(audioDelay, function() {
        playAudio(player);
      });
    }
  }

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

#904

Run the code through JSLint, and you should find that about the only other thing that's needed is a function name for the delay code, which can be easily dealt with by calling it playAfterDelay