-
Notifications
You must be signed in to change notification settings - Fork 22.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a page for HTMLMediaElement.preservesPitch (#14183)
* Add a page for HTMLMediaElement.preservesPitch * Fix slug capitalization * Better headings * Remove an extra space * Adjust see also * Update files/en-us/web/api/htmlmediaelement/index.md argh, copy/paste Co-authored-by: Jean-Yves Perrier <jypenator@gmail.com> * Update files/en-us/web/api/htmlmediaelement/preservespitch/index.md Co-authored-by: Jean-Yves Perrier <jypenator@gmail.com> * Update files/en-us/web/api/htmlmediaelement/preservespitch/index.md Co-authored-by: Jean-Yves Perrier <jypenator@gmail.com> * Remove extraneous empty line Co-authored-by: Jean-Yves Perrier <jypenator@gmail.com>
- Loading branch information
Showing
3 changed files
with
75 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
files/en-us/web/api/htmlmediaelement/preservespitch/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
--- | ||
title: HTMLMediaElement.preservesPitch | ||
slug: Web/API/HTMLMediaElement/preservesPitch | ||
tags: | ||
- API | ||
- HTML DOM | ||
- HTMLMediaElement | ||
- Property | ||
browser-compat: api.HTMLMediaElement.preservesPitch | ||
--- | ||
{{APIRef("HTML DOM")}} | ||
|
||
The **`HTMLMediaElement.preservesPitch`** property determines whether or not the browser should adjust the pitch of the audio to compensate for changes to the playback rate made by setting {{domxref("HTMLMediaElement.playbackRate")}}. | ||
|
||
## Value | ||
|
||
A boolean value defaulting to `true`. | ||
|
||
## Examples | ||
|
||
### Setting the preservesPitch property | ||
|
||
In this example, we have an {{HTMLElement("audio")}} element, a range control that adjusts the playback rate, and a checkbox that sets `preservesPitch`. | ||
|
||
Try playing the audio, then adjusting the playback rate, then enabling and disabling the checkbox. | ||
|
||
```html | ||
<audio controls src="https://mdn.github.io/webaudio-examples/audio-basics/outfoxing.mp3"></audio> | ||
|
||
<div> | ||
<label for="rate">Adjust playback rate:</label> | ||
<input id="rate" type="range" min="0.25" max="3" step="0.05" value="1"> | ||
</div> | ||
|
||
<div> | ||
<label for="pitch">Preserve pitch:</label> | ||
<input type="checkbox" id="pitch" name="pitch" checked> | ||
</div> | ||
``` | ||
|
||
```css hidden | ||
div { | ||
margin: .5rem 0; | ||
} | ||
``` | ||
|
||
```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', () => { | ||
audio.mozPreservesPitch = pitch.checked; | ||
audio.preservesPitch = pitch.checked; | ||
}); | ||
``` | ||
|
||
{{EmbedLiveSample("Setting the preservesPitch property")}} | ||
|
||
## Specifications | ||
|
||
{{Specifications}} | ||
|
||
## Browser compatibility | ||
|
||
{{Compat}} | ||
|
||
## See also | ||
|
||
- {{domxref("HTMLMediaElement.playbackRate")}} | ||
- [Web Audio playbackRate explained](/en-US/docs/Web/Guide/Audio_and_video_delivery/WebAudio_playbackRate_explained) |