如何获取音频元素?

How to get audio element?

使用 React,我希望获取音频元素。

var AudioPlayer = React.createClass({
    componentDidMount: function () {
        console.info('Audio: component did mount');
        var audio = React.findDOMNode('audio');
        console.info('audio', audio);
    },
    render : function() {
        return (
            <audio src="/static/music/foo.mp3" controls />
        );
    }
});

但我一直收到错误消息:

Error: Invariant Violation: Element appears to be neither ReactComponent nor DOMNode (keys: 0,1,2,3,4)

降低的组件肯定是 React 类?

它使用组件引用工作:

var AudioPlayer = React.createClass({
    componentDidMount: function () {
        console.info('[AudioPlayer] componentDidMount...');
        this.props.el = React.findDOMNode(this.refs.audio_tag);
        console.info('audio prop set', this.props.el);
    },
    render: function() {
        console.info('[AudioPlayer] render...');
        return (
            <audio ref="audio_tag" src="/static/music/foo.mp3" controls autoplay="true"/>
        );
    }
});