import React, { Component } from 'react' import { findDOMNode } from 'react-dom' import { hot } from 'react-hot-loader' import screenfull from 'screenfull' import './reset.css' import './defaults.css' import './range.css' import './App.css' import { version } from '../../package.json' import ReactPlayer from '../index' import Duration from './Duration' function isIOS () { return [ 'iPad Simulator', 'iPhone Simulator', 'iPod Simulator', 'iPad', 'iPhone', 'iPod' ].includes(navigator.platform) || // iPad on iOS 13 detection (navigator.userAgent.includes('Mac') && 'ontouchend' in document) } class App extends Component { state = { url: null, pip: false, playing: false, controls: false, light: false, volume: 0.8, muted: false, played: 0, loaded: 0, duration: 0, playbackRate: 1.0, loop: false, config: { amp: { nativeControlsForTouch: isIOS() } } } load = (url, label) => { const newState = { url, played: 0, loaded: 0, pip: false }; if (label === 'Token') { this.urlAmpConfig.value = '{"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1cm46bWljcm9zb2Z0OmF6dXJlOm1lZGlhc2VydmljZXM6Y29udGVudGtleWlkZW50aWZpZXIiOiI5ZGRhMGJjYy01NmZiLTQxNDMtOWQzMi0zYWI5Y2M2ZWE4MGIiLCJpc3MiOiJodHRwOi8vdGVzdGFjcy5jb20vIiwiYXVkIjoidXJuOnRlc3QiLCJleHAiOjE3MTA4MDczODl9.lJXm5hmkp5ArRIAHqVJGefW2bcTzd91iZphoKDwa6w8","manifestProxy":"http://spyros-hls-proxy.azurewebsites.net/api/ManifestLoad"}'; this.urlInput.value = 'https://amssamples.streaming.mediaservices.windows.net/830584f8-f0c8-4e41-968b-6538b9380aa5/TearsOfSteelTeaser.ism/manifest(format=m3u8-aapl)'; newState.config = JSON.parse(this.urlAmpConfig.value); } this.setState(newState) } handlePlayPause = () => { this.setState({ playing: !this.state.playing }) } handleStop = () => { this.setState({ url: null, playing: false }) } handleToggleControls = () => { const url = this.state.url this.setState({ controls: !this.state.controls, url: null }, () => this.load(url)) } handleToggleLight = () => { this.setState({ light: !this.state.light }) } handleToggleLoop = () => { this.setState({ loop: !this.state.loop }) } handleVolumeChange = e => { this.setState({ volume: parseFloat(e.target.value) }) } handleToggleMuted = () => { this.setState({ muted: !this.state.muted }) } handleSetPlaybackRate = e => { this.setState({ playbackRate: parseFloat(e.target.value) }) } handleTogglePIP = () => { this.setState({ pip: !this.state.pip }) } handlePlay = () => { console.log('onPlay') this.setState({ playing: true }) } handleEnablePIP = () => { console.log('onEnablePIP') this.setState({ pip: true }) } handleDisablePIP = () => { console.log('onDisablePIP') this.setState({ pip: false }) } handlePause = () => { console.log('onPause') this.setState({ playing: false }) } handleSeekMouseDown = e => { this.setState({ seeking: true }) } handleSeekChange = e => { this.setState({ played: parseFloat(e.target.value) }) } handleSeekMouseUp = e => { this.setState({ seeking: false }) this.player.seekTo(parseFloat(e.target.value)) } handleProgress = state => { console.log('onProgress', state) // We only want to update time slider if we are not currently seeking if (!this.state.seeking) { this.setState(state) } } handleEnded = () => { console.log('onEnded') this.setState({ playing: this.state.loop }) } handleDuration = (duration) => { console.log('onDuration', duration) this.setState({ duration }) } handleClickFullscreen = () => { screenfull.request(findDOMNode(this.player)) } handleLoadAmpConfigs = (e) => { const amp = JSON.parse(e.currentTarget.value) const config = { amp } config.amp.nativeControlsForTouch = isIOS() console.log(config) this.setState({ config }) } renderLoadButton = (url, label) => { return ( ) } ref = player => { this.player = player } render () { const { url, playing, controls, light, volume, muted, loop, played, loaded, duration, playbackRate, pip, config } = this.state const SEPARATOR = ' ยท ' return (

ReactPlayer Demo

console.log('onReady')} onStart={() => console.log('onStart')} onPlay={this.handlePlay} onEnablePIP={this.handleEnablePIP} onDisablePIP={this.handleDisablePIP} onPause={this.handlePause} onBuffer={() => console.log('onBuffer')} onSeek={e => console.log('onSeek', e)} onEnded={this.handleEnded} onError={e => console.log('onError', e)} onProgress={this.handleProgress} onDuration={this.handleDuration} config={config} playsinline />
Controls {light && } {ReactPlayer.canEnablePIP(url) && }
Speed
Seek
Volume
  Requires player reload
Played
Loaded
YouTube {this.renderLoadButton('https://www.youtube.com/watch?v=oUFJJNQGwhk', 'Test A')} {this.renderLoadButton('https://www.youtube.com/watch?v=jNgP6d9HraI', 'Test B')} {this.renderLoadButton('https://www.youtube.com/playlist?list=PLogRWNZ498ETeQNYrOlqikEML3bKJcdcx', 'Playlist')}
SoundCloud {this.renderLoadButton('https://soundcloud.com/miami-nights-1984/accelerated', 'Test A')} {this.renderLoadButton('https://soundcloud.com/tycho/tycho-awake', 'Test B')} {this.renderLoadButton('https://soundcloud.com/yunghog/sets/doperaptraxxx', 'Playlist')}
Facebook {this.renderLoadButton('https://www.facebook.com/facebook/videos/10153231379946729/', 'Test A')} {this.renderLoadButton('https://www.facebook.com/FacebookDevelopers/videos/10152454700553553/', 'Test B')}
Vimeo {this.renderLoadButton('https://vimeo.com/90509568', 'Test A')} {this.renderLoadButton('https://vimeo.com/169599296', 'Test B')}
Twitch {this.renderLoadButton('https://www.twitch.tv/videos/106400740', 'Test A')} {this.renderLoadButton('https://www.twitch.tv/videos/12783852', 'Test B')} {this.renderLoadButton('https://www.twitch.tv/kronovi', 'Test C')}
Streamable {this.renderLoadButton('https://streamable.com/moo', 'Test A')} {this.renderLoadButton('https://streamable.com/ifjh', 'Test B')}
Wistia {this.renderLoadButton('https://home.wistia.com/medias/e4a27b971d', 'Test A')} {this.renderLoadButton('https://home.wistia.com/medias/29b0fbf547', 'Test B')} {this.renderLoadButton('https://home.wistia.com/medias/bq6epni33s', 'Test C')}
DailyMotion {this.renderLoadButton('https://www.dailymotion.com/video/x5e9eog', 'Test A')} {this.renderLoadButton('https://www.dailymotion.com/video/x61xx3z', 'Test B')}
Mixcloud {this.renderLoadButton('https://www.mixcloud.com/mixcloud/meet-the-curators/', 'Test A')} {this.renderLoadButton('https://www.mixcloud.com/mixcloud/mixcloud-curates-4-mary-anne-hobbs-in-conversation-with-dan-deacon/', 'Test B')}
Vidyard {this.renderLoadButton('https://video.vidyard.com/watch/YBvcF2BEfvKdowmfrRwk57', 'Test A')} {this.renderLoadButton('https://video.vidyard.com/watch/BLXgYCDGfwU62vdMWybNVJ', 'Test B')}
Kaltura {this.renderLoadButton('https://cdnapisec.kaltura.com/p/2507381/sp/250738100/embedIframeJs/uiconf_id/44372392/partner_id/2507381?iframeembed=true&playerId=kaltura_player_1605622074&entry_id=1_jz404fbl', 'Test A')} {this.renderLoadButton('https://cdnapisec.kaltura.com/p/2507381/sp/250738100/embedIframeJs/uiconf_id/44372392/partner_id/2507381?iframeembed=true&playerId=kaltura_player_1605622336&entry_id=1_i1jmzcn3', 'Test B')}
Files {this.renderLoadButton('https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/360/Big_Buck_Bunny_360_10s_1MB.mp4', 'mp4')} {this.renderLoadButton('https://test-videos.co.uk/vids/bigbuckbunny/webm/vp8/360/Big_Buck_Bunny_360_10s_1MB.webm', 'webm')} {this.renderLoadButton('https://filesamples.com/samples/video/ogv/sample_640x360.ogv', 'ogv')} {this.renderLoadButton('https://storage.googleapis.com/media-session/elephants-dream/the-wires.mp3', 'mp3')}
{this.renderLoadButton('https://bitdash-a.akamaihd.net/content/MI201109210084_1/m3u8s/f08e80da-bf1d-4e3d-8899-f0f6155f6efa.m3u8', 'HLS (m3u8)')} {this.renderLoadButton('http://dash.edgesuite.net/envivio/EnvivioDash3/manifest.mpd', 'DASH (mpd)')}
AzureMediaPlayer {this.renderLoadButton('https://amssamples.streaming.mediaservices.windows.net/3b970ae0-39d5-44bd-b3a3-3136143d6435/AzureMediaServicesPromo.ism/manifest', 'No Token')}
{this.renderLoadButton('https://amssamples.streaming.mediaservices.windows.net/830584f8-f0c8-4e41-968b-6538b9380aa5/TearsOfSteelTeaser.ism/manifest(format=m3u8-aapl)', 'Token')}