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


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.

How do I fix that?


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.


What if I added a single piece of code to each of the buttons, can we try that?


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.


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


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.


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


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.


What do you mean?

Would I add something to the code?

How do I do that?


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


Remove the first set of code



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.


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


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.


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.


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.


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


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.


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

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


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.