如何使用客户端库(video.js)进行反应?

时间:2017-08-17 18:03:00

标签: reactjs

您好我正在尝试使用video.js(请参阅http://videojs.com/)作为视频播放器,文档说要添加:

"<link href="//vjs.zencdn.net/5.19/video-js.min.css" rel="stylesheet">"

 "<script src="//vjs.zencdn.net/5.19/video.min.js"></script>"

到我的申请表。我如何在反应中使用它?

另外,在我的public / index.html中:

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0' name='viewport' />
    <meta name="theme-color" content="#000000">
    <link rel="manifest" href="%PUBLIC_URL%/manifest.json">
    <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
    <link href="//vjs.zencdn.net/5.19/video-js.min.css" rel="stylesheet">
    <title>Digitizing POC</title>
  </head>
  <body>
    <noscript>
      You need to enable JavaScript to run this app.
    </noscript>
    <div id="root"></div>

    <script src="//vjs.zencdn.net/5.19/video.min.js"></script>
  </body>
</html>

视频组件:

componentDidMount() {
    let that = this;
    let player = videojs('my-player', options, function onPlayerReady() {
          this.on('canplay',()=>{
            console.log("can play)";
          })         
    });  

}



Error in browser: 
Failed to compile
/src/components/videoplayer.js
  Line 41:  'videojs' is not defined  no-undef

1 个答案:

答案 0 :(得分:1)

React应用index.html

中添加该链接

EDITindex.html

<head>
    <link href="//vjs.zencdn.net/5.19/video-js.min.css" rel="stylesheet">
    <script src="//vjs.zencdn.net/5.19/video.min.js"></script>
</head>

index.js

import React from 'react';
import ReactDOM from 'react-dom';

const App = () => {
return (<video
    id="my-player"
    class="video-js"
    controls
    preload="auto"
    poster="//vjs.zencdn.net/v/oceans.png"
    data-setup='{}'>
  <source src="//vjs.zencdn.net/v/oceans.mp4" type="video/mp4"></source>
  <source src="//vjs.zencdn.net/v/oceans.webm" type="video/webm"></source>
  <source src="//vjs.zencdn.net/v/oceans.ogv" type="video/ogg"></source>
  <p class="vjs-no-js">
    To view this video please enable JavaScript, and consider upgrading to a
    web browser that
    <a href="http://videojs.com/html5-video-support/" target="_blank">
      supports HTML5 video
    </a>
   </p>
  </video>
  );
}

ReactDOM.render(<App />, document.querySelector('.container'));