Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 26745: don't auto-play #26748

Merged
merged 1 commit into from
May 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions files/en-us/web/api/htmlmediaelement/preservespitch/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,23 @@ div {

```js
const audio = document.querySelector("audio");

const rate = document.querySelector("#rate");
rate.addEventListener("input", () => (audio.playbackRate = rate.value));

const pitch = document.querySelector("#pitch");
pitch.addEventListener("change", () => {
if ("preservesPitch" in audio) {
audio.preservesPitch = pitch.checked;
} else if ("mozPreservesPitch" in audio) {
// deprecated
audio.mozPreservesPitch = pitch.checked;
}
});
// 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 }
);
```

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