Skip to content

Commit cb91bd0

Browse files
committed
add documentation to oEmbed meta fetching
1 parent 85ee74e commit cb91bd0

File tree

3 files changed

+79
-1
lines changed

3 files changed

+79
-1
lines changed

doc/readme.md

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@
5656
- [getAvailablePlaybackRates](#getAvailablePlaybackRates)
5757
- [seekTo](#seekTo)
5858

59+
### module methods
60+
61+
- [getYoutubeMeta](#getYoutubeMeta)
62+
5963
# Reference
6064

6165
## height
@@ -312,7 +316,7 @@ returns a promise that resolves to a list of available playback rates.
312316

313317
The array of numbers are ordered from slowest to fastest playback speed. Even if the player does not support variable playback speeds, the array should always contain at least one value (1).
314318

315-
# seekTo
319+
## seekTo
316320

317321
`seekTo(seconds:Number, allowSeekAhead:Boolean):Void`
318322

@@ -326,3 +330,40 @@ The `allowSeekAhead` parameter determines whether the player will make a new req
326330
We recommend that you set this parameter to false while the user drags the mouse along a video progress bar and then set it to true when the user releases the mouse. This approach lets a user scroll to different points of a video without requesting new video streams by scrolling past unbuffered points in the video. When the user releases the mouse button, the player advances to the desired point in the video and requests a new video stream if necessary.
327331

328332
https://developers.google.com/youtube/iframe_api_reference#seekTo
333+
334+
# Module methods
335+
336+
## getYoutubeMeta
337+
338+
`getYoutubeMeta(videoId: String): Promise<youtubeMeta>`
339+
340+
Fetch metadata of a youtube video using the oEmbed Spec - https://oembed.com/#section7
341+
342+
metadata returned -
343+
344+
| field | type | explanation |
345+
| ---------------- | ------ | -------------------------------------------------- |
346+
| author_name | String | The name of the author/owner of the video. |
347+
| author_url | String | youtube channel link of the video |
348+
| height | Number | The height in pixels required to display the HTML. |
349+
| html | String | The HTML required to embed a video player. |
350+
| provider_name | String | The name of the resource provider. |
351+
| provider_url | String | The url of the resource provider. |
352+
| thumbnail_height | Number | The height of the video thumbnail. |
353+
| thumbnail_url | String | The url of the resource provider. |
354+
| thumbnail_width | Number | The width of the video thumbnail. |
355+
| title | String | youtube video title |
356+
| type | String | The oEmbed version number. |
357+
| version | String | The resource type. |
358+
| width | Number | The width in pixels required to display the HTML. |
359+
360+
example -
361+
362+
```javascript
363+
import {Alert} from 'react-native';
364+
import {getYoutubeMeta} from 'react-native-youtube-iframe';
365+
366+
getYoutubeMeta('sNhhvQGsMEc').then(meta => {
367+
Alert.alert('title of the video : ' + meta.title);
368+
});
369+
```

readme.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ A wrapper of the Youtube IFrame player API build for react native.
77
- ✅ Uses the webview player which is known to be more stable compared to the native youtube app
88
- ✅ Access to a vast API provided through the iframe youtube API
99
- ✅ Supports multiple youtube player instances in a single page
10+
- ✅ Fetch basic video metadata without API keys (uses oEmbed)
1011
- ✅ Works on modals and overlay components
1112

1213
## Prerequisite
@@ -73,6 +74,8 @@ list of available APIs -
7374
- playbackRate
7475
- onPlaybackRateChange
7576
- initialPlayerParams
77+
- webViewStyle
78+
- webViewProps
7679

7780
### Ref functions
7881

@@ -84,6 +87,10 @@ list of available APIs -
8487
- getAvailablePlaybackRates
8588
- seekTo
8689

90+
## methods
91+
92+
- getYoutubeMeta
93+
8794
## Contributing
8895

8996
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

src/oEmbed.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,36 @@
1919
* Fetch metadata of a youtube video using the oEmbed Spec -
2020
* https://oembed.com/#section7
2121
*
22+
* metadata -
23+
*
24+
* `thumbnail_url` - The url of the resource provider.
25+
*
26+
* `thumbnail_width` - The width of the video thumbnail.
27+
*
28+
* `thumbnail_height` - The height of the video thumbnail.
29+
*
30+
* `height` - The height in pixels required to display the HTML.
31+
*
32+
* `width` - The width in pixels required to display the HTML.
33+
*
34+
* `html` - The HTML required to embed a video player.
35+
*
36+
* `author_url` - youtube channel link of the video
37+
*
38+
* `title` - youtube video title
39+
*
40+
* `provider_name` - The name of the resource provider.
41+
*
42+
* `author_name` - The name of the author/owner of the video.
43+
*
44+
* `provider_url` - The url of the resource provider.
45+
*
46+
* `version` - The oEmbed version number.
47+
*
48+
* `type` - The resource type.
49+
*
50+
*
51+
*
2252
* @param {String} videoId - youtube video id
2353
* @returns {Promise<youtubeMeta>} A promise that resolves into an object with the video metadata
2454
*/

0 commit comments

Comments
 (0)