Skip to content

Commit 873b541

Browse files
committed
update readme and homepage
1 parent 203b6c7 commit 873b541

File tree

4 files changed

+137
-34
lines changed

4 files changed

+137
-34
lines changed

doc/readme.md

Lines changed: 105 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,33 +27,33 @@
2727

2828
### props
2929

30-
- height
31-
- width
32-
- ref
33-
- videoId
34-
- playList,
35-
- playListStartIndex,
36-
- play
37-
- onChangeState
38-
- onReady
39-
- onError
40-
- onPlaybackQualityChange
41-
- mute
42-
- volume
43-
- playbackRate
44-
- onPlaybackRateChange
45-
- initialPlayerParams
46-
- webViewStyle
30+
- [height](#height)
31+
- [width](#width)
32+
- [ref](#ref)
33+
- [videoId](#videoId)
34+
- [playList](#playList)
35+
- [playListStartIndex](#playListStartIndex)
36+
- [play](#play)
37+
- [onChangeState](#onChangeState)
38+
- [onReady](#onReady)
39+
- [onError](#onError)
40+
- [onPlaybackQualityChange](#onPlaybackQualityChange)
41+
- [mute](#mute)
42+
- [volume](#volume)
43+
- [playbackRate](#playbackRate)
44+
- [onPlaybackRateChange](#onPlaybackRateChange)
45+
- [initialPlayerParams](#initialPlayerParams)
46+
- [webViewStyle](#webViewStyle)
4747

4848
### Ref functions
4949

50-
- getDuration
51-
- getCurrentTime
52-
- isMuted
53-
- getVolume
54-
- getPlaybackRate
55-
- getAvailablePlaybackRates
56-
- seekTo
50+
- [getDuration](#getDuration)
51+
- [getCurrentTime](#getCurrentTime)
52+
- [isMuted](#isMuted)
53+
- [getVolume](#getVolume)
54+
- [getPlaybackRate](#getPlaybackRate)
55+
- [getAvailablePlaybackRates](#getAvailablePlaybackRates)
56+
- [seekTo](#seekTo)
5757

5858
# Reference
5959

@@ -124,7 +124,7 @@ Flag to tell the player to play or pause the video.
124124
Make sure you match this flag `onChangeState` to handle user pausing
125125
the video from the youtube player UI
126126

127-
> The HTML5 <video> element, in certain mobile browsers (such as Chrome and Safari), only allows playback to take place if it's initiated by a user interaction (such as tapping on the player).
127+
> **note on autoPlay**: The HTML5 `<video>` element, in certain mobile browsers (such as Chrome and Safari), only allows playback to take place if it's initiated by a user interaction (such as tapping on the player).
128128
129129
## onChangeState
130130

@@ -230,3 +230,83 @@ The `playbackRate` that the API passes to the event listener function will be a
230230
## webViewStyle
231231

232232
A style prop that will be given to the webview
233+
234+
# Ref functions
235+
236+
usage -
237+
238+
```javascript
239+
import React, {useRef} from 'react';
240+
const App = () => {
241+
const playerRef = useRef();
242+
return (
243+
<YoutubePlayer height={400} width={400} ref={playerRef} videoId={'AVAc1gYLZK0'} />
244+
<Button
245+
title="log details"
246+
onPress={() => {
247+
248+
playerRef.current.getCurrentTime().then(currentTime => console.log({currentTime}));
249+
250+
playerRef.current.getDuration().then(getDuration => console.log({getDuration}));
251+
252+
playerRef.current.isMuted().then(isMuted => console.log({isMuted}));
253+
254+
playerRef.current.getVolume().then(getVolume => console.log({getVolume}));
255+
256+
playerRef.current.getPlaybackRate().then(getPlaybackRate => console.log({getPlaybackRate}));
257+
258+
playerRef.current.getAvailablePlaybackRates().then(getAvailablePlaybackRates => console.log({getAvailablePlaybackRates}
259+
));
260+
261+
}}
262+
/>
263+
);
264+
};
265+
```
266+
267+
## getDuration
268+
269+
returns a promise that resolves to the total duration of the video
270+
271+
Note that getDuration() will return 0 until the video's metadata is loaded, which normally happens just after the video starts playing.
272+
273+
If the currently playing video is a live event, the getDuration() function will resolve the elapsed time since the live video stream began. Specifically, this is the amount of time that the video has streamed without being reset or interrupted. In addition, this duration is commonly longer than the actual event time since streaming may begin before the event's start time.
274+
275+
## getCurrentTime
276+
277+
returns a promise that resolves to the elapsed time in seconds since the video started playing.
278+
279+
## isMuted
280+
281+
returns a promise that resolves to true if the video is muted, false if not.
282+
283+
## getVolume
284+
285+
returns a promise that resolves to the player's current volume, an integer between 0 and 100. Note that `getVolume()` will return the volume even if the player is muted.
286+
287+
## getPlaybackRate
288+
289+
returns a promise that resolves to the current playback rate of the video.
290+
291+
The default playback rate is 1, which indicates that the video is playing at normal speed. Playback rates may include values like 0.25, 0.5, 1, 1.5, and 2.
292+
293+
## getAvailablePlaybackRates
294+
295+
returns a promise that resolves to a list of available playback rates.
296+
297+
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).
298+
299+
# seekTo
300+
301+
`seekTo(seconds:Number, allowSeekAhead:Boolean):Void`
302+
303+
Seeks to a specified time in the video. If the player is paused when the function is called, it will remain paused. If the function is called from another state (playing, video cued, etc.), the player will play the video.
304+
The seconds parameter identifies the time to which the player should advance.
305+
306+
The player will advance to the closest keyframe before that time unless the player has already downloaded the portion of the video to which the user is seeking.
307+
308+
The `allowSeekAhead` parameter determines whether the player will make a new request to the server if the seconds parameter specifies a time outside of the currently buffered video data.
309+
310+
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.
311+
312+
https://developers.google.com/youtube/iframe_api_reference#seekTo

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-youtube-iframe",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"description": "A simple wrapper around the youtube iframe js API for react native",
55
"main": "index.js",
66
"scripts": {
@@ -29,7 +29,7 @@
2929
"bugs": {
3030
"url": "https://github.com/LonelyCpp/react-native-youtube-iframe/issues"
3131
},
32-
"homepage": "https://github.com/LonelyCpp/react-native-youtube-iframe#readme",
32+
"homepage": "https://lonelycpp.github.io/react-native-youtube-iframe/",
3333
"peerDependencies": {
3434
"react-native-webview": "^7.5.2",
3535
"react": ">=16.8.0",

readme.md

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,40 @@ This package uses react-hooks and therefore will need **react-native `0.59` and
3737

3838
## API reference
3939

40-
[Here](./doc)
40+
[Click here for full reference here](./doc)
41+
42+
list of available APIs -
43+
44+
### props
45+
46+
- videoId
47+
- playList
48+
- playListStartIndex
49+
- play
50+
- onChangeState
51+
- onReady
52+
- onError
53+
- onPlaybackQualityChange
54+
- mute
55+
- volume
56+
- playbackRate
57+
- onPlaybackRateChange
58+
- initialPlayerParams
59+
60+
### Ref functions
61+
62+
- getDuration
63+
- getCurrentTime
64+
- isMuted
65+
- getVolume
66+
- getPlaybackRate
67+
- getAvailablePlaybackRates
68+
- seekTo
4169

4270
## Contributing
4371

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

46-
Please make sure to update tests as appropriate.
47-
4874
## License
4975

5076
[MIT](https://choosealicense.com/licenses/mit/)

src/YoutubeIframe.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,6 @@ const YoutubeIframe = (
8484
webViewRef.current.injectJavaScript(
8585
PLAYER_FUNCTIONS.seekToScript(seconds, allowSeekAhead),
8686
);
87-
return new Promise(resolve => {
88-
eventEmitter.current.once('getAvailablePlaybackRates', resolve);
89-
});
9087
},
9188
}),
9289
[],
@@ -166,7 +163,7 @@ const YoutubeIframe = (
166163
return (
167164
<View style={{height, width}}>
168165
<WebView
169-
style={[webViewStyle, styles.webView]}
166+
style={[styles.webView, webViewStyle]}
170167
ref={webViewRef}
171168
originWhitelist={['*']}
172169
source={{html: MAIN_SCRIPT(videoId, playList, initialPlayerParams)}}

0 commit comments

Comments
 (0)