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


#1207

Do you know how to fix the above issue?

The audio does not stop when I click on the 2nd player.

Click on the 1st player first.

Then click on the 2nd player.
https://jsfiddle.net/19htLogp/1/

How do I fix that?


#1208

It results in more problems to have multiple sets of code controlling the same buttons, because coordinating those different sets of code to work together requires a lot of complex changes.

How we fix the above issue is to combine both sets of code so that the one set controls both of the buttons instead.


#1209

What if I added a single piece of code to each of the buttons, can we try that?
https://jsfiddle.net/27jz1dzy/15/


#1210

With the way that the code is going, you'll end up with two different sets of code, that both need to know how to control both buttons, and both fight each other for that control. If you're looking for worst ways of doing things, I don't know of many other ways that are worse.


#1211

Maybe I'm better off not using a time delay on it then.


#1212

The time delay has been simplified, and the amount of delay is being passed in from the event handler. That can look at info such as whether an initial image is used, and only use a time delay then. The delay can otherwise be 0 when used without an initial image. It's a system that works well.


#1213

Currently, that's how it's set up. Time delay only on the initial image.


#1214

Exactly, and that time delay code can use a delay of 0 when the button it's dealing with has no initial image. It's a simple system that doesn't break, and works well.


#1215

What do you mean?

Would I add something to the code?
https://jsfiddle.net/27jz1dzy/15/

How do I do that?


#1216

Remove the first set of code, and we'll use the second set to control both the first and the second button.


#1217

Remove the first set of code

huh??


#1218

You currently have five buttons and five different sets of JavaScript code. The plan is for the second set of JavaScript code to control the first and second buttons, thus removing the need to have that first set of JavaScript code.

Or in other words, code B will be used to control button A&B, with a plan for it to eventually control all of the buttons.


#1219

What about the 3rd 4th 5th and 6th javascript?


#1220

Those can remain as they are for now, and we will gradually merge them in to the main code, so that we end up with just one set of code that controls everything.


#1221

As you can see from this Diff between code A and code B, there's more code in code B. It will be easier to modify code B so that it can do what code A does as well.


#1222

If you want to use Diff to compare two sets of code, it helps if spacing and formatting problems are identical across the code, so using JSLint to clean up the code first before using Diff, results in very easy comparisons between code.


#1223

That's not my plan, my plan is to have individual javascripts for each player.


#1224

Instead of multiplying the power of JavaScript, you're going to negate any and all power that it might have? What a terrible way to go.


#1225

It's easier, because, what if I change the players, or remove a couple.

I won't know what to change in the javascript.


#1226

I think I understand the issue that you are facing. This is where tests become incredibly useful.

Not only do tests easily help to ensure that your code continues to work, but when you remove a player you can remove the tests for that player, and code-coverage tools then tell you what parts of your script no longer need to be there.