reat中使用videojs

直播组件

import React, { Component } from 'react';
import videojs from 'video.js';
import 'video.js/dist/video-js.min.css';
import "./live.less";
var ActiveXObject=window.ActiveXObject;
class Live extends Component {
    constructor(props){
        super(props);
    }
    componentDidMount() {
        //判断浏览器是否有flash插件
        var isIE=false;
        if(window.ActiveXObject){
            isIE=true;
        }
        var has_flash=false;
        try{
            if(isIE){
                var flash=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
                has_flash=true;
            }else{
                var flash=navigator.plugins["Shockwave Flash"];
                if(flash){
                    has_flash=true;
                }
            }
        }catch (e) {
            console.log(e);
        }
        if(has_flash){
            var _this=this;
            //在局域网不能播放,添加的代码,引入的路径必须是用require引入(使用本地的swf或者                    
               node_modules里面的都是可以的),不是局域网的就不用写这行代码,
           videojs.options.flash.swf = require('videojs-swf/dist/video-js.swf');
           // videojs.options.flash.swf = require("本地地址路径");
            this.player = videojs(this.videoNode, {
                preload: 'auto',// 预加载
                bigPlayButton: {},// 大按钮
                controls: true,// 是否开启控制栏
                width: 850,// 播放器宽度
                height: 600,// 播放器高度
                playbackRates: [1, 1.5, 2],
                muted: true, //是否静音
                loop : false, //是否循环播放
                autoplay:true, //是否自动播放
                techOrder: ["flash"],//设置flash播放
                language: "zh-CN",
            }, function onPlayerReady() {
                if(_this.props.videostreaming){
                    this.src({
                        src: "直播地址”,
                        type:'rtmp/flv'
                    })
                }
            });
        }
    componentWillUnmount() {
        if (this.player) {
            this.player.dispose();
        }
    }
    render() {
        return(
            <div data-vjs-player>
                <video ref={ node => this.videoNode = node } className="video-js vjs-big-play-centered" id="myvideo" poster={flash}></video>
            </div>
        );
    }
}
export default Live;

 在局域网不能播放,添加的代码,引入的路径必须是用require引入(使用本地的swf或者node_modules里面的都是可以的),不是局域网的就不用写这行代码,
           videojs.options.flash.swf = require('videojs-swf/dist/video-js.swf');

我使用的是video.js@5.8.2版本,之前使用的是video.js@5.20.4,这个版本静音和播放放大直播画面,鼠标放上去显示英文,video.js@5.8.2是没有的,看自己的需求了

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值