npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@linkdesign/video

v0.0.2

Published

> @linkdesign/video 是基于video.js和react封装的视频播放控件

Downloads

6

Readme

@linkdesign/video

@linkdesign/video 是基于video.js和react封装的视频播放控件

特性

@linkdesign/video 可以在react项目中使用, 可以支持HTML5和Flash视频

如果想在原生js项目中使用请参考案例./example

浏览器兼容

目前兼容主流浏览器, 谷歌浏览器 IE11以上最新版本 EDGE浏览器 rtmp视频流再火狐浏览器中存在兼容问题, 其他浏览器需要开启flash插件才能正常播放rtmp视频 safari 浏览器需要开启flash插件 如何开启

快速开始

在React中使用video

# Install deps
$ npm install @linkdesign/video --save

安装好依赖后可以在项目中使用

import React from 'react';
import { Video } from '@linkdesign/video';

const option = {
  autoplay: false,
  controls: true,
  width: 500,
  height: 300,
  techorder: ['flash', 'html5'],
  source: [{
    src: 'rtmp://58.200.131.2:1935/livetv/hunantv',
    type: 'rtmp/mp4',
  }]
}
function Demo() {
  return (
    <div >
      <Video option={option} onReady={(ref) => { // ref为播放器实例 }}/>
    </div>
  );
}

export default Demo;

在html中使用video

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8" />
  <title>rtmp直播流播放</title>
  <link href="https://unpkg.com/[email protected]/dist/video-js.min.css" rel="stylesheet" type="text/css">
  <script src="https://unpkg.com/[email protected]/dist/video.min.js"></script>
  <!--rtmp需要加载flash的插件 -->
  <script src="https://cdn.jsdelivr.net/npm/videojs-flash@2/dist/videojs-flash.min.js"></script>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    .content {
      width: 800px;
      height: 450px;
    }
  </style>
</head>

<body>
  <div class="content">
    <video id="vid1" controls preload="auto"
      class="video-js vjs-default-skin vjs-big-play-centered vjs-fluid vjs-16-9 videoElement">
      <source src="rtmp://58.200.131.2:1935/livetv/hunantv" type="rtmp/mp4">
    </video>
  </div>

  <script>
    var vid = document.getElementById('vid1');
    var player = videojs(vid, {
      autoplay: false,
      controls: true,
      techorder: ['flash', 'html5']
    });
  </script>

</body>

</html>

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8" />
  <title>视频播放</title>
  <link href="https://unpkg.com/[email protected]/dist/video-js.min.css" rel="stylesheet" type="text/css">
  <script src="https://unpkg.com/[email protected]/dist/video.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/videojs-flash@2/dist/videojs-flash.min.js"></script>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    .content {
      width: 800px;
      height: 450px;
    }
  </style>
</head>

<body>
  <div class="content">
    <video id="vid1" controls preload="auto"
      class="video-js vjs-default-skin vjs-big-play-centered vjs-fluid vjs-16-9 videoElement">
      <source src="http://img.ksbbs.com/asset/Mon_1703/d30e02a5626c066.mp4" type="video/mp4">
    </video>
  </div>

  <script>
    var vid = document.getElementById('vid1');
    var player = videojs(vid);
  </script>

</body>

</html>

option常用配置

autoplay : true/false 播放器准备好之后,是否自动播放 【默认false】
controls : true/false 是否拥有控制条 【默认true】,如果设为false ,那么只能通过api进行控制了。也就是说界面上不会出现任何控制按钮
height: 视频容器的高度,字符串或数字 单位像素 比如: height:300 or height:‘300px‘
width: 视频容器的宽度, 字符串或数字 单位像素
loop : true/false 视频播放结束后,是否循环播放
muted : true/false 是否静音
poster: 播放前显示的视频画面,播放开始之后自动移除。通常传入一个URL
preload:预加载 ‘auto‘ 自动 | ’metadata‘ 元数据信息 ,比如视频长度,尺寸等 | ‘none‘ 不预加载任何数据,直到用户开始播放才开始下载
source: 播放的资源
techOrder:

option常用详解

autoplay

类型: boolean 如果true/作为属性存在,则在播放器准备就绪时开始播放。

注意:从iOS 10开始,Apple autoplay在Safari中提供支持。有关详细信息,请参阅“新增功能。

controls

类型: boolean 确定播放器是否具有用户可以与之交互的控件。没有控件,启动视频播放的唯一方法是使用autoplay属性或通过Player API。

height

类型: string|number 设置视频播放器的显示高度(以像素为单位)。

loop

类型: boolean 使视频一结束就重新开始。

muted

类型: boolean 默认情况下会静音任何音频。

poster

类型: string 在视频开始播放之前显示的图像的URL。这通常是视频的框架或自定义标题屏幕。一旦用户点击“播放”,图像就会消失。

preload

类型: string 建议浏览器是否应在加载元素后立即开始下载视频数据。支持的值是: ‘auto’ 立即开始加载视频(如果浏览器支持)。某些移动设备不会预加载视频,以保护用户的带宽/数据使用。这就是为什么这个价值被称为’汽车’,而不是更具决定性的东西’true’。 这往往是最常见和推荐的值,因为它允许浏览器选择最佳行为。 ‘metadata’ 仅加载视频的元数据,其中包括视频的持续时间和尺寸等信息。有时,元数据将通过下载几帧视频来加载。 ‘none’ 不要预加载任何数据。浏览器将等待用户点击“播放”开始下载。

source

类型: Array

一组对象,它们反映了本机元素具有一系列子元素的能力。这应该是带有src和type属性的对象数组。例如:


[{
  src: '//path/to/video.mp4',
  type: 'video/mp4'
}, {
  src: '//path/to/video.webm',
  type: 'video/webm'
}]

width

类型: string|number 设置视频播放器的显示宽度(以像素为单位)。

techOrder

输入:Array,默认值:[‘html5’, 'flash']

定义Video.js技术首选的顺序。默认情况下,这意味着Html5首选技术。其他注册的技术将在此技术之后按其注册顺序添加。

flash

swf 指定Video.js SWF文件在Flash技术位置的位置:

flash: {
  swf: '//path/to/videojs.swf'
}

但是,更改全局默认值通常更合适:

videojs.options.flash.swf = ‘//path/to/videojs.swf’

/* 如果是rtmp的直播流, video.js默认的buffer缓存是1秒钟, 如果想要清除缓存可以设置 */

bufferTime: 0,
flash: {
  flashVars: {
    bufferTime: 0,
    autoPlay: true,
    bufferTimeMax: 0.25,
  },
},

Video.js特定的选项

aspectRatio

类型: string 将播放器置于流体模式,并在计算播放器的动态大小时使用该值。该值应表示比率 - 由冒号(例如"16:9"或"4:3")分隔的两个数字。

autoSetup

类型: boolean 阻止播放器为具有data-setup属性的媒体元素运行autoSetup 。

注意:必须在与videojs.options.autoSetup = falsevideojs源加载生效的同一时刻全局设置。

children

类型: Array|Object 此选项继承自基Component类。

fluid

类型: boolean 何时true,Video.js播放器将具有流畅的大小。换句话说,它将扩展以适应其容器。

此外,如果元素具有"vjs-fluid",则此选项自动设置为true。

inactivityTimeout

类型: number Video.js表示用户通过"vjs-user-active"和"vjs-user-inactive"类以及"useractive"事件与玩家进行交互。

在inactivityTimeout决定了不活动的许多毫秒声明用户闲置之前是必需的。值为0表示没有inactivityTimeout,用户永远不会被视为非活动状态。

language

键入:string,默认值:浏览器默认值或’en’ 与播放器中的一种可用语言匹配的语言代码。这为播放器设置了初始语言,但始终可以更改。

在Video.js中了解有关语言的更多信息。

languages

类型: Object 自定义播放器中可用的语言。此对象的键将是语言代码,值将是具有英语键和翻译值的对象。

在Video.js中了解有关语言的更多信息

注意:通常,不需要此选项,最好将自定义语言传递给videojs.addLanguage()所有玩家!

nativeControlsForTouch

类型: boolean 明确设置关联技术选项的默认值。

notSupportedMessage

类型: string 允许覆盖Video.js无法播放媒体源时显示的默认消息。