Skip to content

Commit

Permalink
make preservesPitch example functional (#27509)
Browse files Browse the repository at this point in the history
* make example functional

* Update index.md

---------

Co-authored-by: Joshua Chen <sidachen2003@gmail.com>
  • Loading branch information
marcelblum and Josh-Cena authored Jun 23, 2023
1 parent 4f4624a commit 5cbf16f
Showing 1 changed file with 6 additions and 17 deletions.
23 changes: 6 additions & 17 deletions files/en-us/web/api/htmlmediaelement/preservespitch/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,12 @@ div {

```js
const audio = document.querySelector("audio");
// When the audio starts playing...
audio.addEventListener(
"play",
() => {
// Handle page visibility change:
// - If the page is hidden, pause the video
// - If the page is shown, play the video
document.addEventListener("visibilitychange", () => {
if (document.hidden) {
audio.pause();
} else {
audio.play();
}
});
},
{ once: true }
);
document.getElementById("rate").addEventListener("change", (e) => {
audio.playbackRate = e.target.value;
});
document.getElementById("pitch").addEventListener("change", (e) => {
audio.preservesPitch = e.target.checked;
});
```

{{EmbedLiveSample("Setting the preservesPitch property")}}
Expand Down

0 comments on commit 5cbf16f

Please sign in to comment.