$(document).ready(function() {
"use strict";
if ($('#waveform1').length) {
var wavesurfer1 = WaveSurfer.create({
container: '#waveform1',
waveColor: '#0E61B4',
progressColor: '#30A5E0',
fillParent: false,
minPxPerSec: 10,
height: 85,
barMinHeight: 26,
hideScrollbar: true,
cursor: true,
responsive: true,
});
// Load an audio file
var song = 'http://ia902606.us.archive.org/35/items/shortpoetry_047_librivox/song_cjrg_teasdale_64kb.mp3';
wavesurfer1.load(song);
waveform1.getElementsByTagName("wave")[1].style.border = 'none';
// change icon and paues and play song
$(".controls-waveform1 .button-play-audio").on('click', function() {
if (wavesurfer1.isPlaying()) {
wavesurfer1.pause();
playSong1.style.display = "block";
pauseSong1.style.display = "none";
} else {
wavesurfer1.play();
playSong1.style.display = "none";
pauseSong1.style.display = "block";
}
});
}
// WaveSurfer2
if ($('#waveform2').length) {
var wavesurfer2 = WaveSurfer.create({
container: '#waveform2',
waveColor: '#0E61B4',
progressColor: '#30A5E0',
fillParent: false,
minPxPerSec: 10,
height: 85,
barMinHeight: 26,
hideScrollbar: true,
cursor: true,
responsive: true,
});
// Load an audio file
var song2 = 'http://ia902606.us.archive.org/35/items/shortpoetry_047_librivox/song_cjrg_teasdale_64kb.mp3';
wavesurfer2.load(song2);
waveform2.getElementsByTagName("wave")[1].style.border = 'none';
// change icon and paues and play song
$(".controls-waveform2 .button-play-audio").on('click', function() {
if (wavesurfer2.isPlaying()) {
wavesurfer2.pause();
playSong2.style.display = "block";
pauseSong2.style.display = "none";
} else {
wavesurfer2.play();
playSong2.style.display = "none";
pauseSong2.style.display = "block";
}
});
}
The code works fine and everything is fine, but I want the second sound to play and the first sound to be paused if it's already playing. I just want one of them to work and not to get played together. [1]: https://i.stack.imgur.com/Ou1me.png