Skip to content

Commit

Permalink
add documentation to oEmbed meta fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
LonelyCpp committed Mar 10, 2020
1 parent 85ee74e commit cb91bd0
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 1 deletion.
43 changes: 42 additions & 1 deletion doc/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@
- [getAvailablePlaybackRates](#getAvailablePlaybackRates)
- [seekTo](#seekTo)

### module methods

- [getYoutubeMeta](#getYoutubeMeta)

# Reference

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

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).

# seekTo
## seekTo

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

Expand All @@ -326,3 +330,40 @@ The `allowSeekAhead` parameter determines whether the player will make a new req
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.

https://developers.google.com/youtube/iframe_api_reference#seekTo

# Module methods

## getYoutubeMeta

`getYoutubeMeta(videoId: String): Promise<youtubeMeta>`

Fetch metadata of a youtube video using the oEmbed Spec - https://oembed.com/#section7

metadata returned -

| field | type | explanation |
| ---------------- | ------ | -------------------------------------------------- |
| author_name | String | The name of the author/owner of the video. |
| author_url | String | youtube channel link of the video |
| height | Number | The height in pixels required to display the HTML. |
| html | String | The HTML required to embed a video player. |
| provider_name | String | The name of the resource provider. |
| provider_url | String | The url of the resource provider. |
| thumbnail_height | Number | The height of the video thumbnail. |
| thumbnail_url | String | The url of the resource provider. |
| thumbnail_width | Number | The width of the video thumbnail. |
| title | String | youtube video title |
| type | String | The oEmbed version number. |
| version | String | The resource type. |
| width | Number | The width in pixels required to display the HTML. |

example -

```javascript
import {Alert} from 'react-native';
import {getYoutubeMeta} from 'react-native-youtube-iframe';

getYoutubeMeta('sNhhvQGsMEc').then(meta => {
Alert.alert('title of the video : ' + meta.title);
});
```
7 changes: 7 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ A wrapper of the Youtube IFrame player API build for react native.
- ✅ Uses the webview player which is known to be more stable compared to the native youtube app
- ✅ Access to a vast API provided through the iframe youtube API
- ✅ Supports multiple youtube player instances in a single page
- ✅ Fetch basic video metadata without API keys (uses oEmbed)
- ✅ Works on modals and overlay components

## Prerequisite
Expand Down Expand Up @@ -73,6 +74,8 @@ list of available APIs -
- playbackRate
- onPlaybackRateChange
- initialPlayerParams
- webViewStyle
- webViewProps

### Ref functions

Expand All @@ -84,6 +87,10 @@ list of available APIs -
- getAvailablePlaybackRates
- seekTo

## methods

- getYoutubeMeta

## Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Expand Down
30 changes: 30 additions & 0 deletions src/oEmbed.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,36 @@
* Fetch metadata of a youtube video using the oEmbed Spec -
* https://oembed.com/#section7
*
* metadata -
*
* `thumbnail_url` - The url of the resource provider.
*
* `thumbnail_width` - The width of the video thumbnail.
*
* `thumbnail_height` - The height of the video thumbnail.
*
* `height` - The height in pixels required to display the HTML.
*
* `width` - The width in pixels required to display the HTML.
*
* `html` - The HTML required to embed a video player.
*
* `author_url` - youtube channel link of the video
*
* `title` - youtube video title
*
* `provider_name` - The name of the resource provider.
*
* `author_name` - The name of the author/owner of the video.
*
* `provider_url` - The url of the resource provider.
*
* `version` - The oEmbed version number.
*
* `type` - The resource type.
*
*
*
* @param {String} videoId - youtube video id
* @returns {Promise<youtubeMeta>} A promise that resolves into an object with the video metadata
*/
Expand Down

0 comments on commit cb91bd0

Please sign in to comment.