1import * as React from 'react' 2import {Props} from './audio-video' 3 4class AudioVideo extends React.Component<Props> { 5 private vidRef = React.createRef<HTMLVideoElement>() 6 7 seek = (seconds: number) => { 8 if (this.vidRef.current) { 9 this.vidRef.current.currentTime = seconds 10 if (this.props.paused) { 11 this.vidRef.current.pause() 12 } 13 } 14 } 15 16 componentDidUpdate(prevProps: Props) { 17 if (!this.vidRef.current) { 18 return 19 } 20 if (this.props.paused && !prevProps.paused) { 21 this.vidRef.current.pause() 22 } else if (!this.props.paused && prevProps.paused) { 23 this.vidRef.current.play() 24 } 25 } 26 27 render() { 28 return <video ref={this.vidRef} src={this.props.url} style={{height: 0, width: 0}} /> 29 } 30} 31 32export default AudioVideo 33