summaryrefslogtreecommitdiff
path: root/client/src/lib/components/youtube.js
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2017-06-01 19:47:08 -0400
committerJules Laplace <julescarbon@gmail.com>2017-06-01 19:47:08 -0400
commit3e72bfa56c860826429a842f6c128d78d4a930db (patch)
tree3cecd31c92d53fae32e9761b80802c82f3dcb7fa /client/src/lib/components/youtube.js
parentb694bd511ceccd00d4a4c98f36f910d5fc5f79c4 (diff)
react-native-web port of fmf app
Diffstat (limited to 'client/src/lib/components/youtube.js')
-rw-r--r--client/src/lib/components/youtube.js91
1 files changed, 91 insertions, 0 deletions
diff --git a/client/src/lib/components/youtube.js b/client/src/lib/components/youtube.js
new file mode 100644
index 0000000..ab5f8aa
--- /dev/null
+++ b/client/src/lib/components/youtube.js
@@ -0,0 +1,91 @@
+import React, { Component } from 'react';
+import {
+} from 'react-native';
+
+export default class Youtube extends Component {
+ constructor(props) {
+ super()
+ this.container = null
+ this.buildPlayer = this.buildPlayer.bind(this)
+ }
+ render() {
+ return (
+ <div ref={(ref) => this.container = ref} />
+ )
+ }
+ componentDidMount() {
+ if (YT_READY) {
+ this.buildPlayer()
+ }
+ else {
+ setTimeout(this.buildPlayer, 250)
+ }
+ }
+ buildPlayer() {
+ this.player = new YT.Player(this.container, {
+ videoId: this.props.ytid,
+ width: "100%",
+ height: 400,
+ playerVars: {
+ 'autohide': 1,
+ 'autoplay': 0,
+ 'disablekb': 0,
+ 'cc_load_policy': 3,
+ 'controls': 0,
+ 'enablejsapi': 1,
+ 'fs': 0,
+ 'modestbranding': 1,
+ 'iv_load_policy': 3,
+ 'loop': 0,
+ 'showinfo': 0,
+ 'rel': 0,
+ 'wmode': 'transparent',
+ 'hd': 1
+ },
+ events: {
+ onReady: function(e){
+ e.target.playVideo()
+ },
+ onStateChange: function(e){
+ switch(e.data){
+ case -1:
+ // unstarted
+ break
+ case 0:
+ // finished
+ break
+ case 1:
+ // play
+ break
+ case 2:
+ // pause
+ break
+ case 3:
+ // buffering
+ break
+ case 5:
+ // cued
+ break
+ default:
+ break
+ }
+ }
+ }
+ })
+ }
+ componentDidUpdate(prevProps, prevState) {
+ if (! this.player) {
+ return
+ }
+ else if (prevProps.ytid !== this.props.ytid) {
+ this.player.loadVideoById( this.props.ytid )
+ }
+ }
+}
+
+let YT_READY = false
+
+global.onYouTubeIframeAPIReady = function(){
+ console.log('youtube api loaded')
+ YT_READY = true
+}