aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/AudioBox.tsx
blob: 689d44a2f3a4e7b067da73fc200b76c4d0e2f7e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import React = require("react");
import { FieldViewProps, FieldView } from './FieldView';
import { observer } from "mobx-react";
import "./AudioBox.scss";
import { Cast } from "../../../new_fields/Types";
import { AudioField } from "../../../new_fields/URLField";
import { DocStaticComponent } from "../DocComponent";
import { makeInterface } from "../../../new_fields/Schema";
import { documentSchema } from "./DocumentView";
import { InkingControl } from "../InkingControl";

type AudioDocument = makeInterface<[typeof documentSchema]>;
const AudioDocument = makeInterface(documentSchema);
const defaultField: AudioField = new AudioField(new URL("http://techslides.com/demos/samples/sample.mp3"));

@observer
export class AudioBox extends DocStaticComponent<FieldViewProps, AudioDocument>(AudioDocument) {

    public static LayoutString() { return FieldView.LayoutString(AudioBox); }
    _ref = React.createRef<HTMLAudioElement>();

    componentDidMount() {
        if (this._ref.current) this._ref.current.currentTime = 1;
    }

    render() {
        let field = Cast(this.props.Document[this.props.fieldKey], AudioField, defaultField);
        let path = field.url.href;

        let interactive = this.active() ? "-interactive" : "";
        return (
            <div className="audiobox-container">
                <audio controls ref={this._ref} className={`audiobox-control${interactive}`}>
                    <source src={path} type="audio/mpeg" />
                    Not supported.
                </audio>
            </div>
        );
    }
}