Skip to content

Instantly share code, notes, and snippets.

@berkaytheunicorn
Created January 18, 2017 08:37
Show Gist options
  • Save berkaytheunicorn/a04bf76e65e603ed1a27047330b81fee to your computer and use it in GitHub Desktop.
Save berkaytheunicorn/a04bf76e65e603ed1a27047330b81fee to your computer and use it in GitHub Desktop.
React Video Component
React = require "react"
{video,source} = React.DOM
View = React.createClass
displayName: "Video"
shouldComponentUpdate:(nextProps,nextState)->
# unless @refs.video.readyState is 4
# return true
# unless @props.options.style.width is nextProps.options.style.width
# return true
# unless @props.options.style.height is nextProps.options.style.height
# return true
# return false
return true
# componentDidMount:()->
# @refs.video.load()
# console.log "yey"
componentDidUpdate:()->
unless @refs.video.readyState is 4
@refs.video.load()
options:()->
props = @props.options
props.ref = "video"
return props
render: ()->
video @options() ,
@props.sources.map (video,index)->
source
key:index
src: video.src
type: video.type or ""
module.exports = React.createFactory View
@berkaytheunicorn
Copy link
Author

berkaytheunicorn commented Jan 18, 2017

Usage:

Video
	options:
		className:"content-gif"
		poster:"#{@props.block.data.fileUrl}?frame=1"
		loop:true
		controls:false
		autoPlay:true
		style: @gifStyle()
	sources:[
			src:"#{@props.block.data.fileUrl}?fm=mp4"
			type:"video/mp4"
	]

in JSX

<Video options={ options } sources={ sources } />

@berkaytheunicorn
Copy link
Author

Important part is

 unless @refs.video.readyState is 4
  @refs.video.load()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment