I am facing an issue with the text not displaying in the "play-stop-toggle" element, despite my limited experience with JS.
My desired outcome includes:
- [SOLVED] The text in
should toggle between<div id="play-stop-toggle" onclick="togglePlay()">Play</div>
PLAY
andSTOP
when clicked, - As a result,
Tone.Transport.stop()
andTone.Transport.start()
must toggle to control the playback of sound invar filter = new Tone.Filter
.
The current issue is that the text toggles from PLAY to STOP on the first click but then fails to toggle back. Additionally, there is no sound output.
function togglePlay() {
Tone.Transport.toggle();
const status = Tone.Transport.state; // Is either 'started', 'stopped' or 'paused'
const element = document.getElementById("play-stop-toggle");
if (status == "started") {
element.innerText = "STOP";
Tone.Transport.stop()
} else {
element.innerText = "PLAY";
Tone.Transport.start()
}
}
var filter = new Tone.Filter({
type: 'lowpass',
Q: 12
}).toMaster()
body,
html {
height: 100%;
margin: 5em;
background-color: black;
}
h1 {
font-size: 2.1rem;
/* text-align: center !important; */
font-family: 'Courier New', Courier, monospace;
margin: 0px;
color: ghostwhite;
padding-bottom: 20px;
font-weight: bold;
text-align: justify;
}
p {
margin: 0;
font-size: 2rem;
font-family: 'Courier New', Courier, monospace;
color: ghostwhite;
padding-bottom: 20px;
text-align: justify;
font-weight: bold;
}
p.sig {
margin: 0;
font-size: 2rem;
font-family: 'Courier New', Courier, monospace;
color: ghostwhite;
padding-bottom: 20px;
text-align: right;
}
div.bodycontent {
margin: 0px;
padding: 0px;
width: 375px;
position: absolute;
top: 50%;
left: 50%;
margin-right: -50%;
transform: translate(-50%, -50%);
display: none;
}
a:link,
a:visited {
/* background-color: #f44336; */
color: white;
text-align: center;
font-style: italic;
text-decoration: underline;
display: inline-block;
cursor: pointer;
}
a:hover,
a:active {
background-color: white;
color: black;
cursor: pointer;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ccb8a3a2a98cfdffe2f4e2fef9">[email protected]</a>/build/Tone.js"></script>
<script src="p1-fish.js"></script>
<link rel="stylesheet" type="text/css" href="ristyle.css">
</head>
<body>
<div class="bg">
<h1>Heading</h1>
<p>Text</p>
</div>
<div id="play-stop-toggle" onclick="togglePlay()">Play</div>
</body>
</html>