diff options
| author | yipstanley <stanley_yip@brown.edu> | 2019-03-17 14:23:00 -0400 |
|---|---|---|
| committer | yipstanley <stanley_yip@brown.edu> | 2019-03-17 14:23:00 -0400 |
| commit | 3d337129f112425345436aa69a95fcf03ad830d7 (patch) | |
| tree | f156445b8f5afad577e4038a849290d755a8d552 /src/client/views/nodes/VideoBox.tsx | |
| parent | b4dc598ff08c7c684daa4b75508e17213d29d8e5 (diff) | |
| parent | 47da497aded0bafdc5c85c8a79a9a06d0d401e92 (diff) | |
Merge branch 'master' of https://github.com/browngraphicslab/Dash-Web into view_doc_impl
Diffstat (limited to 'src/client/views/nodes/VideoBox.tsx')
| -rw-r--r-- | src/client/views/nodes/VideoBox.tsx | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/client/views/nodes/VideoBox.tsx b/src/client/views/nodes/VideoBox.tsx new file mode 100644 index 000000000..8c1ee669f --- /dev/null +++ b/src/client/views/nodes/VideoBox.tsx @@ -0,0 +1,61 @@ +import React = require("react") +import { observer } from "mobx-react"; +import { FieldWaiting } from '../../../fields/Field'; +import { VideoField } from '../../../fields/VideoField'; +import { FieldView, FieldViewProps } from './FieldView'; +import "./VideoBox.scss"; +import Measure from "react-measure"; +import { action, trace, observable } from "mobx"; +import { KeyStore } from "../../../fields/KeyStore"; +import { number } from "prop-types"; + +@observer +export class VideoBox extends React.Component<FieldViewProps> { + + public static LayoutString() { return FieldView.LayoutString(VideoBox) } + + constructor(props: FieldViewProps) { + super(props); + } + + + _loaded: boolean = false; + + @action + setScaling = (r: any) => { + if (this._loaded) { + // bcz: the nativeHeight should really be set when the document is imported. + // also, the native dimensions could be different for different pages of the PDF + // so this design is flawed. + var nativeWidth = this.props.doc.GetNumber(KeyStore.NativeWidth, 0); + var nativeHeight = this.props.doc.GetNumber(KeyStore.NativeHeight, 0); + var newNativeHeight = nativeWidth * r.entry.height / r.entry.width; + if (!nativeHeight && newNativeHeight != nativeHeight && !isNaN(newNativeHeight)) { + this.props.doc.SetNumber(KeyStore.Height, newNativeHeight / nativeWidth * this.props.doc.GetNumber(KeyStore.Width, 0)); + this.props.doc.SetNumber(KeyStore.NativeHeight, newNativeHeight); + } + } else { + this._loaded = true; + } + } + + + + render() { + let field = this.props.doc.Get(this.props.fieldKey) + let path = field == FieldWaiting ? "http://techslides.com/demos/sample-videos/small.mp4" : + field instanceof VideoField ? field.Data.href : "http://techslides.com/demos/sample-videos/small.mp4"; + + //setTimeout(action(() => this._loaded = true), 500); + return ( + <Measure onResize={this.setScaling}> + {({ measureRef }) => + <video className="videobox-cont" ref={measureRef}> + <source src={path} type="video/mp4" /> + Not supported. + </video> + } + </Measure> + ) + } +}
\ No newline at end of file |
