You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is **no need** to build or commit files in `dist` after making changes. The `dist` files are only there for [bower](http://bower.io) support, and there is very little point in polluting every commit or pull request with the changes. The `dist` files will be automatically built and commmited when new versions are released, so your changes will be included then.
A React component for playing a variety of URLs, including file paths, YouTube, Facebook, Twitch, SoundCloud, Streamable, Vimeo, Wistia and DailyMotion.
11
-
12
-
The component parses a URL and loads in the appropriate markup and external SDKs to play media from [various sources](#supported-media). [Props](#props) can be passed in to control playback and react to events such as buffering or media ending.
A React component for playing a variety of URLs, including file paths, YouTube, Facebook, Twitch, SoundCloud, Streamable, Vimeo, Wistia and DailyMotion.
25
+
</p>
13
26
14
27
#### Migrating to `1.0.0`
15
28
16
29
All existing implementations of `ReactPlayer` should still work without any changes after migrating. The major changes are to how the component works internally. Keep an eye out for bugs and [raise an issue](https://github.com/CookPete/react-player/issues/new) if one doesn’t already exist.
17
30
18
-
### Polyfills
19
-
20
-
* If you are using `npm` and need to support [browsers without `Promise`](http://caniuse.com/#feat=promises) you will need a [`Promise` polyfill](https://github.com/stefanpenner/es6-promise).
21
-
* To support IE11 you will need to use [`babel-polyfill`](https://babeljs.io/docs/usage/polyfill) or a similar ES2015+ polyfill.
22
-
23
31
### Usage
24
32
25
33
```bash
@@ -39,45 +47,16 @@ class App extends Component {
39
47
}
40
48
```
41
49
42
-
See [the demo source](https://github.com/CookPete/react-player/blob/master/src/demo/App.js) for a full example.
43
-
44
-
For platforms like [Meteor](https://www.meteor.com) without direct use of `npm` modules, a minified version of `ReactPlayer` is located in `dist` after installing. To generate this file yourself, checkout the repo and run `npm run build:dist`
See a [live demo](http://cookpete.com/react-player), or run:
52
+
The component parses a URL and loads in the appropriate markup and external SDKs to play media from [various sources](#supported-media). [Props](#props) can be passed in to control playback and react to events such as buffering or media ending. See [the demo source](https://github.com/CookPete/react-player/blob/master/src/demo/App.js) for a full example.
For platforms like [Meteor](https://www.meteor.com) without direct use of `npm` modules, a minified version of `ReactPlayer` is located in `dist` after installing. To generate this file yourself, checkout the repo and run `npm run build:dist`.
77
55
78
-
Due to various restrictions, `ReactPlayer` is not guaranteed to function properly on mobile devices. The [YouTube player documentation](https://developers.google.com/youtube/iframe_api_reference), for example, explains that [certain mobile browsers require user interaction](https://developers.google.com/youtube/iframe_api_reference#Mobile_considerations) before playing:
56
+
#### Polyfills
79
57
80
-
> 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).
58
+
* If you are using `npm` and need to support [browsers without `Promise`](http://caniuse.com/#feat=promises) you will need a [`Promise` polyfill](https://github.com/stefanpenner/es6-promise).
59
+
* To support IE11 you will need to use [`babel-polyfill`](https://babeljs.io/docs/usage/polyfill) or a similar ES2015+ polyfill.
81
60
82
61
### Props
83
62
@@ -90,8 +69,8 @@ Prop | Description | Default
90
69
`volume` | Sets the volume of the appropriate player | `0.8`
91
70
`muted` | Mutes the player | `false`
92
71
`playbackRate` | Sets the playback rate of the appropriate player<br />*Note: Only supported by YouTube, Wistia, and file paths* | `1`
93
-
`width` | Sets the width of the player | `640`
94
-
`height` | Sets the height of the player | `360`
72
+
`width` | Sets the width of the player | `640px`
73
+
`height` | Sets the height of the player | `360px`
95
74
`style` | Add [inline styles](https://facebook.github.io/react/tips/inline-styles.html) to the root element | `{}`
96
75
`progressFrequency` | The time between `onProgress` callbacks, in milliseconds | `1000`
97
76
`playsinline` | Applies the `playsinline` attribute where supported | `false`
@@ -158,6 +137,107 @@ Key | Options
158
137
159
138
When `preload` is set to `true` for players that support it, a short, silent video is played in the background when `ReactPlayer` first mounts. This fixes a [bug](https://github.com/CookPete/react-player/issues/7) where videos would not play when loaded in a background browser tab.
160
139
140
+
### Methods
141
+
142
+
#### Static Methods
143
+
144
+
Method | Description
145
+
---- | -----------
146
+
`ReactPlayer.canPlay(url)` | Determine if a URL can be played. This does *not* detect media that is unplayable due to privacy settings, streaming permissions, etc. In that case, the `onError` prop will be invoked after attemping to play. Any URL that does not match any patterns will fall back to a native HTML5 media player.
147
+
148
+
#### Instance Methods
149
+
150
+
Use [`ref`](https://facebook.github.io/react/docs/refs-and-the-dom.html) to call instance methods on the player. See [the demo app](src/demo/App.js) for an example of this.
151
+
152
+
Method | Description
153
+
---- | -----------
154
+
`seekTo(amount)` | Seek to the given number of seconds, or fraction if `amount` is between `0` and `1`
155
+
`getCurrentTime()` | Returns the number of seconds that has been played<br /> ◦ Returns `null` if duration is unavailable
156
+
`getDuration()` | Returns the duration (in seconds) of the currently playing media<br /> ◦ Returns `null` if duration is unavailable
157
+
`getInternalPlayer()` | Returns the internal player of whatever is currently playing<br /> ◦ eg the [YouTube player instance](https://developers.google.com/youtube/iframe_api_reference#Loading_a_Video_Player), or the [`<video>`](https://developer.mozilla.org/en/docs/Web/HTML/Element/video) element when playing a video file<br /> ◦ Use `getInternalPlayer('hls')` to get the [hls.js](https://github.com/video-dev/hls.js) player<br /> ◦ Use `getInternalPlayer('dash')` to get the [dash.js](https://github.com/Dash-Industry-Forum/dash.js) player<br /> ◦ Returns `null` if the internal player is unavailable
158
+
159
+
### Advanced Usage
160
+
161
+
#### Responsive player
162
+
163
+
Set `width` and `height` to `100%` and wrap the player in a [fixed aspect ratio box](https://css-tricks.com/aspect-ratio-boxes) to get a responsive player:
164
+
165
+
```js
166
+
classResponsivePlayerextendsComponent {
167
+
render () {
168
+
return (
169
+
<div className='player-wrapper'>
170
+
<ReactPlayer
171
+
className='react-player'
172
+
url='https://www.youtube.com/watch?v=ysz5S6PUM-U'
173
+
width='100%'
174
+
height='100%'
175
+
/>
176
+
</div>
177
+
)
178
+
}
179
+
}
180
+
```
181
+
182
+
```css
183
+
.player-wrapper {
184
+
position: relative;
185
+
padding-top: 56.25%/* Player ratio: 100 / (1280 / 720) */
186
+
}
187
+
188
+
.react-player {
189
+
position: absolute;
190
+
top: 0;
191
+
left: 0;
192
+
}
193
+
```
194
+
195
+
See [`jsFiddle` example](https://jsfiddle.net/e6w3rtj1/)
196
+
197
+
#### Standalone player
198
+
199
+
If you aren’t using React, you can still render a player using the standalone library:
<ReactPlayer url='https://www.youtube.com/watch?v=d46Azg3Pm4c' playing />,
230
+
document.getElementById('container')
231
+
)
232
+
</script>
233
+
```
234
+
235
+
#### Mobile considerations
236
+
237
+
Due to various restrictions, `ReactPlayer` is not guaranteed to function properly on mobile devices. The [YouTube player documentation](https://developers.google.com/youtube/iframe_api_reference), for example, explains that [certain mobile browsers require user interaction](https://developers.google.com/youtube/iframe_api_reference#Mobile_considerations) before playing:
238
+
239
+
> 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).
240
+
161
241
#### Multiple Sources and Tracks
162
242
163
243
When playing file paths, an array of sources can be passed to the `url` prop to render multiple `<source>` tags.
@@ -194,45 +274,25 @@ You can also specify a `type` for each source by using objects with `src` and `t
194
274
/>
195
275
```
196
276
197
-
198
-
### Methods
199
-
200
-
#### Static Methods
201
-
202
-
Method | Description
203
-
---- | -----------
204
-
`ReactPlayer.canPlay(url)` | Determine if a URL can be played. This does *not* detect media that is unplayable due to privacy settings, streaming permissions, etc. In that case, the `onError` prop will be invoked after attemping to play. Any URL that does not match any patterns will fall back to a native HTML5 media player.
205
-
206
-
#### Instance Methods
207
-
208
-
Use [`ref`](https://facebook.github.io/react/docs/refs-and-the-dom.html) to call instance methods on the player. See [the demo app](src/demo/App.js) for an example of this.
209
-
210
-
Method | Description
211
-
---- | -----------
212
-
`seekTo(amount)` | Seek to the given number of seconds, or fraction if `amount` is between `0` and `1`
213
-
`getCurrentTime()` | Returns the number of seconds that has been played<br /> ◦ Returns `null` if duration is unavailable
214
-
`getDuration()` | Returns the duration (in seconds) of the currently playing media<br /> ◦ Returns `null` if duration is unavailable
215
-
`getInternalPlayer()` | Returns the internal player of whatever is currently playing<br /> ◦ eg the [YouTube player instance](https://developers.google.com/youtube/iframe_api_reference#Loading_a_Video_Player), or the [`<video>`](https://developer.mozilla.org/en/docs/Web/HTML/Element/video) element when playing a video file<br /> ◦ Use `getInternalPlayer('hls')` to get the [hls.js](https://github.com/video-dev/hls.js) player<br /> ◦ Use `getInternalPlayer('dash')` to get the [dash.js](https://github.com/Dash-Industry-Forum/dash.js) player<br /> ◦ Returns `null` if the internal player is unavailable
216
-
217
277
### Supported media
218
278
219
279
* YouTube videos use the [YouTube iFrame Player API](https://developers.google.com/youtube/iframe_api_reference)
220
280
* Facebook videos use the [Facebook Embedded Video Player API](https://developers.facebook.com/docs/plugins/embedded-video-player/api)
221
281
* SoundCloud tracks use the [SoundCloud Widget API](https://developers.soundcloud.com/docs/api/html5-widget)
222
-
* Streamable videos are [resolved](https://streamable.com/documentation#retrieve-video) and played in a [`<video>`](https://developer.mozilla.org/en/docs/Web/HTML/Element/video) element using the track’s `mp4` path
282
+
* Streamable videos use [`Player.js`](https://github.com/embedly/player.js)
223
283
* Vidme videos are [no longer supported](https://medium.com/vidme/goodbye-for-now-120b40becafa)
224
284
* Vimeo videos use the [Vimeo Player API](https://developer.vimeo.com/player/js-api)
225
285
* Wistia videos use the [Wistia Player API](https://wistia.com/doc/player-api)
226
286
* Twitch videos use the [Twitch Interactive Frames API](https://dev.twitch.tv/docs/embed#interactive-frames-for-live-streams-and-vods)
227
287
* DailyMotion videos use the [DailyMotion Player API](https://developer.dailymotion.com/player)
228
288
*[Supported file types](https://developer.mozilla.org/en-US/docs/Web/HTML/Supported_media_formats) are playing using [`<video>`](https://developer.mozilla.org/en/docs/Web/HTML/Element/video) or [`<audio>`](https://developer.mozilla.org/en/docs/Web/HTML/Element/audio) elements
229
-
* HLS streams are played using [hls.js](https://github.com/video-dev/hls.js)
230
-
* DASH streams are played using [dash.js](https://github.com/Dash-Industry-Forum/dash.js)
289
+
* HLS streams are played using [`hls.js`](https://github.com/video-dev/hls.js)
290
+
* DASH streams are played using [`dash.js`](https://github.com/Dash-Industry-Forum/dash.js)
231
291
232
292
### Contributing
233
293
234
294
See the [contribution guidelines](https://github.com/CookPete/react-player/blob/master/CONTRIBUTING.md) before creating a pull request.
235
295
236
296
### Thanks
237
297
238
-
Huge thanks to anyone who has [contributed](https://github.com/CookPete/react-player/graphs/contributors)
298
+
Huge thanks to anyone who has [contributed](https://github.com/CookPete/react-player/graphs/contributors).
0 commit comments