|
27 | 27 |
|
28 | 28 | ### props |
29 | 29 |
|
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) |
47 | 47 |
|
48 | 48 | ### Ref functions |
49 | 49 |
|
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) |
57 | 57 |
|
58 | 58 | # Reference |
59 | 59 |
|
@@ -124,7 +124,7 @@ Flag to tell the player to play or pause the video. |
124 | 124 | Make sure you match this flag `onChangeState` to handle user pausing |
125 | 125 | the video from the youtube player UI |
126 | 126 |
|
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). |
128 | 128 |
|
129 | 129 | ## onChangeState |
130 | 130 |
|
@@ -230,3 +230,83 @@ The `playbackRate` that the API passes to the event listener function will be a |
230 | 230 | ## webViewStyle |
231 | 231 |
|
232 | 232 | 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 |
0 commit comments