Skip to content

Commit f5b6903

Browse files
committed
Fix issues in createVideo/Audio docs + types
1 parent eb7b7df commit f5b6903

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

docs/parameterData.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@
773773
"createVideo": {
774774
"overloads": [
775775
[
776-
"String|String[]",
776+
"String|String[]?",
777777
"Function?"
778778
]
779779
]

src/dom/p5.MediaElement.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,7 +1400,7 @@ function media(p5, fn){
14001400
* the video is ready to play.
14011401
*
14021402
* @method createVideo
1403-
* @param {String|String[]} src path to a video file, or an array of paths for
1403+
* @param {String|String[]} [src] path to a video file, or an array of paths for
14041404
* supporting different browsers.
14051405
* @param {Function} [callback] function to call once the video is ready to play.
14061406
* @return {p5.MediaElement} new <a href="#/p5.MediaElement">p5.MediaElement</a> object.
@@ -1483,11 +1483,11 @@ function media(p5, fn){
14831483
* `createAudio()` returns a new
14841484
* <a href="#/p5.MediaElement">p5.MediaElement</a> object.
14851485
*
1486-
* The first parameter, `src`, is the path the video. If a single string is
1487-
* passed, as in `'assets/video.mp4'`, a single video is loaded. An array
1488-
* of strings can be used to load the same video in different formats. For
1489-
* example, `['assets/video.mp4', 'assets/video.ogv', 'assets/video.webm']`.
1490-
* This is useful for ensuring that the video can play across different
1486+
* The first parameter, `src`, is the path the audio. If a single string is
1487+
* passed, as in `'assets/audio.mp3'`, a single audio is loaded. An array
1488+
* of strings can be used to load the same audio in different formats. For
1489+
* example, `['assets/audio.mp3', 'assets/video.wav']`.
1490+
* This is useful for ensuring that the audio can play across different
14911491
* browsers with different capabilities. See
14921492
* <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Supported_media_formats" target="_blank">MDN</a>
14931493
* for more information about supported formats.

utils/patch.mjs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,25 @@ export function applyPatches() {
7474
`,
7575
);
7676

77+
// Type .elt more specifically for audio and video elements
78+
replace(
79+
'p5.d.ts',
80+
`class MediaElement extends Element {
81+
elt: HTMLAudioElement | HTMLVideoElement;`,
82+
`class MediaElement<T extends HTMLElement = HTMLAudioElement | HTMLVideoElement> extends Element {
83+
elt: T;`,
84+
);
85+
replace(
86+
['p5.d.ts', 'global.d.ts'],
87+
/createAudio\(src\?: string \| string\[\], callback\?: Function\): ([pP]5)\.MediaElement;/g,
88+
'createAudio(src?: string | string[], callback?: (video: $1.MediaElement<HTMLAudioElement>) => any): $1.MediaElement<HTMLAudioElement>;',
89+
);
90+
replace(
91+
['p5.d.ts', 'global.d.ts'],
92+
/createVideo\(src\?: string \| string\[\], callback\?: Function\): ([pP]5)\.MediaElement;/g,
93+
'createVideo(src?: string | string[], callback?: (video: $1.MediaElement<HTMLVideoElement>) => any): $1.MediaElement<HTMLVideoElement>;',
94+
);
95+
7796
for (const [path, data] of Object.entries(patched)) {
7897
try {
7998
console.log(`Patched ${path}`);

0 commit comments

Comments
 (0)