Created
October 5, 2018 13:24
-
-
Save diuis/fc1c2f0e255538cda397c5a6b669c9bf to your computer and use it in GitHub Desktop.
react video element iOS autoplay
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from "react"; | |
import { Container, Row, Col } from 'reactstrap'; | |
import '../styles/video-react.css' | |
export interface ApplicationProps { url: string; } | |
export class Application extends React.Component<ApplicationProps, {}> { | |
private videoNode: HTMLVideoElement; | |
componentDidMount() { | |
console.log('component did mount'); | |
console.log('original video default muted : ' + this.videoNode.defaultMuted); | |
this.videoNode.defaultMuted = true; | |
console.log('changed video default muted : ' + this.videoNode.defaultMuted); | |
this.webcam(); | |
} | |
componentDidCatch() { | |
console.log('component did catch'); | |
} | |
componentDidUpdate() { | |
console.log('component did update'); | |
} | |
private webcam() { | |
if (navigator.mediaDevices.getUserMedia) { | |
navigator.mediaDevices.getUserMedia({ video: { facingMode: "user" }, audio: false }).then(stream => { this.videoNode.srcObject = stream }); | |
} else { | |
console.warn('user media not available'); | |
} | |
} | |
render() { | |
console.log('render'); | |
const h = window.innerHeight; | |
const w = window.innerWidth; | |
return ( | |
<Container> | |
<Row> | |
<Col> | |
<div className="scene"> | |
<div className="panel-face-1"> | |
<video muted autoPlay playsInline width={'90%'} height={'auto'} ref={node => this.videoNode = node} /> | |
</div> | |
</div> | |
</Col> | |
</Row> | |
</Container > | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment