• Stars
    star
    300
  • Rank 138,870 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 5 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🍭 FlvPlayer.js is a JavaScript player for decode flv to the canvas

FlvPlayer

Build Status version license size npm Downloads PRs Welcome dependencies Status

FlvPlayer.js is a JavaScript player for decode flv to the canvas

Homepage

https://flvplayer.js.org

Mobile Demo

Mobile Demo

Install player

Install with npm

$ npm install flvplayer

Or install with yarn

$ yarn add flvplayer
import FlvPlayer from 'flvplayer';

Or umd builds are also available

<script src="path/to/flvplayer.js"></script>

Will expose the global variable to window.FlvPlayer.

Install control(optional)

You should load the control before load the player.

import 'path/to/flvplayer-control.js';

Or umd builds are also available

<script src="path/to/flvplayer-control.js"></script>

Will expose the global variable to window.FlvplayerControl.

Usage

<div class="flvplayer-app"></div>
if (FlvPlayer.isSupported()) {
    var flv = new FlvPlayer({
        // Accept http url, websocket url, and file type
        url: '',

        // Accept dom element, dom selector
        container: '',

        // Video poster url
        poster: '',

        // Whether to print debug information
        debug: false,

        // Whether live mode
        live: false,

        // Whether the video loops, in non-live mode
        loop: false,

        // Whether to use hotkeys, if the control exists
        hotkey: true,

        // Whether to turn off the volume
        muted: false,

        // On the mobile side, try to activate the audio after the user touches the screen.
        touchResume: true,

        // Video chunk size, the default is 1M
        videoChunk: 1024 * 1024,

        // Audio chunk size, the default is 16kb
        audioChunk: 16 * 1024,

        // Whether to play automatically
        autoPlay: false,

        // Whether it contains an audio stream
        hasAudio: true,

        // Whether to cache the video frame to play
        cache: true,

        // Maximum time difference between audio and video, unit is ms
        // used to automatically adjust audio and video synchronization
        maxTimeDiff: 200,

        // Whether to display the control, if the control exists
        control: true,

        // Indicates whether to do http fetching with cookies
        withCredentials: true,

        // Indicates total file size of media file, in bytes
        filesize: Infinity,

        // Indicates whether to enable CORS for http fetching
        cors: true,

        // Volume from 0 to 1, the default is 0.7
        volume: 0.7,

        // Initialize the frame rate, which will be covered by the actual frame rate of the file
        frameRate: 30,

        // Initialize the width, which will be covered by the actual width of the file
        width: 400,

        // Initialize the height, which will be covered by the actual height of the file
        height: 300,

        // Initialize http headers
        headers: {},

        // The path of the video decoder, currently optional flvplayer-decoder-baseline.js and flvplayer-decoder-multiple.js
        decoder: 'flvplayer-decoder-baseline.js',
    });
} else {
    console.warn('Your browser does not support Flvplayer.js');
}

Question

Q: What is the difference between flvplayer-decoder-baseline.js and flvplayer-decoder-multiple.js.

  • flvplayer-decoder-baseline.js only supports flv in this Baseline profile, only 200k size.
  • flvplayer-decoder-multiple.js supports flv in this BaselineMainExtended and High profile, but have 2M size.

API

Instance methods and properties

Play video:

flv.play();

Pause video:

flv.pause();

Switch whether to play:

flv.toggle();

Destroy instance:

flv.destroy();

Whether it is playing:

flv.playing;

Is the stream being pulled:

flv.streaming;

Get the current time of the video:

flv.currentTime;

Get the duration of the video:

flv.duration;

Get the loaded of the video:

flv.loaded;

Whether it is focus:

flv.isFocus;

Set whether to turn off the volume:

flv.muted;

Set the volume:

flv.volume;

Get canvas elements:

flv.$canvas;

Instance event

Name Description
destroy When destroying an instance
streamStart Start pulling the stream
streaming When pulling stream
streamEnd At the end of the pull stream
demuxDone Demux completed
resize When container resize
play When video play
timeupdate When video timeupdate
waiting When video waiting
ended When video ended
loop When video loop
pause When video pause
seeked When video seeked
ready When video ready
streamRate Stream Rate
demuxRate Demux Rate
decoderRate Decoder Rate
drawRate Draw Rate

Example:

flv.on('play', function () {
    console.log('Video is play!');
});

Class methods and properties

Get all instances:

FlvPlayer.instances;

Check if support:

FlvPlayer.isSupported;

Get the version:

FlvPlayer.version;

Get the env:

FlvPlayer.env;

Contribution

Installation dependency

$ npm install

Run the developer mode

$ npm run dev

Open web server

$ npm start

Donations

We accept donations through these channels:

pay

QQ Group

QQ Group

License

MIT © Harvey Zack

More Repositories

1

ArtPlayer

🎨 ArtPlayer.js is a modern and full featured HTML5 video player
JavaScript
2,453
star
2

SubPlayer

📝 SubPlayer is an online subtitle editor
JavaScript
932
star
3

live-video-study-notes

📺 整理前端视频直播相关技术的笔记,适合想入门前端流媒体技术的人阅读
591
star
4

WFPlayer

🌊 WFPlayer.js is an audio waveform generator
JavaScript
260
star
5

bilibili-live-hime

🍓 Chrome 扩展 - Bilibili 直播姬
JavaScript
222
star
6

Teahouse-Wordpress-Theme

🍵 Wordpress blog theme Teahouse
PHP
105
star
7

100plugins

💯 Write 100 javascript plugins
JavaScript
40
star
8

blank

Generate blank video online
JavaScript
17
star
9

term-web

📟 A simple Terminal UI that run on the web
JavaScript
17
star
10

v2ex-card

Chrome 扩展 - v2ex 悬停名片
JavaScript
16
star
11

snippets-box

📒 Code snippet manager based on GitHub Gist, Github Pages
JavaScript
16
star
12

chrome-audio-capture

Chrome Audio Capture
JavaScript
15
star
13

pluto

Wordpress 博客主题 Pluto 源码
PHP
14
star
14

mse-player

基于MSE实现的视频分段加载播放器
TypeScript
14
star
15

traitor

有内鬼,终止交易!
JavaScript
13
star
16

bilibili-live-recorder

Bilibili 直播间录播姬
JavaScript
12
star
17

chrome-extension-vuexTree

一个Chrome扩展,为 Vuex 实现类似 redux-devtools-extension 的状态树展示效果
JavaScript
10
star
18

RNHearthstone

React Native 《炉石传说》查卡App
JavaScript
7
star
19

duration-time-conversion

Duration and time format conversion
JavaScript
6
star
20

console.log

console.log
JavaScript
5
star
21

island

Wordpress 博客主题 Island 源码
PHP
5
star
22

record-hime

🎈 Chrome 扩展 - 录播姬
JavaScript
5
star
23

owl

Wordpress 博客主题 Owl 源码
PHP
4
star
24

flv-reader

🍬 [WIP] Parse flv to fmp4 for Media Source Extension
JavaScript
3
star
25

csp-generator

Content Security Policy Generator
JavaScript
3
star
26

dida.js

An audio stream blender for the browser.
JavaScript
3
star
27

http-flv-streaming-demo

http-flv 直播流例子
Dockerfile
3
star
28

puppeteer-crx

Use puppeteer to package chrome extensions(.crx)
JavaScript
3
star
29

rollup-plugin-worker-inline

A simple rollup plugin to create inline worker
JavaScript
3
star
30

gloom

Wordpress 博客主题 Gloom 源码
PHP
3
star
31

website-builder

多页面静态网站生成器
JavaScript
3
star
32

option-validator

A simple option validator
JavaScript
3
star
33

Webpack-MultiplePage

Webpack多页面打包分析
JavaScript
2
star
34

gitting

💬 Gitting is a modern comment component based on Github Issue.
JavaScript
2
star
35

bilibili-danmuku

获取B站弹幕
JavaScript
2
star
36

nodejs-quick-view

NodeJS文档快速预览
JavaScript
2
star
37

obj-to-string

对象转字符串(非JSON)
JavaScript
2
star
38

detect-connection-speed

Detect connection speed with JavaScript
JavaScript
2
star
39

simple-observer

A simple observer with ES6 Proxy
JavaScript
2
star
40

assets-cdn

CDN资源中转站
2
star
41

Express-mongoose-Passport

使用Express搭建一个简易的全栈管理系统
JavaScript
2
star
42

table-export-zip

打包下载分割的表格
JavaScript
2
star
43

hitokoto-cli

A Hitokoto Cli Tool (一言命令行工具)
JavaScript
2
star
44

html-layout-webpack-plugin

webpack html 布局插件
JavaScript
1
star
45

srt.js

📺 Let the html5 video player support .srt format subtitles.
JavaScript
1
star
46

simple-i18n-webpack-plugin

webpack i18n plugin (webpack i18n 多语言插件)
JavaScript
1
star
47

island-cli

Island blog system command line tool
JavaScript
1
star
48

bilibili-cinema

🎥 Chrome 扩展 - Bilibili 影院点播系统
1
star
49

island-cli-theme-default

Island blog default theme
CSS
1
star
50

js-quick-view

JavaScript 标准库快速浏览
JavaScript
1
star
51

zhw2590582

1
star
52

blur-image-url

JavaScript
1
star
53

online-code-editor

HTML
1
star
54

threejs-template

Threejs Template
JavaScript
1
star
55

aimu-statistics

JavaScript
1
star
56

island-loader

A island loader for webpack
JavaScript
1
star
57

weibo-backup

Chrome 扩展 - 微博备份工具
1
star
58

auto-update-from-github

Auto update from github
JavaScript
1
star
59

island-cli-init

Island blog initialization framework
JavaScript
1
star
60

brusher-html

Wordpress 博客主题 Brusher 静态文件
JavaScript
1
star
61

mini-speed-chart

Detect connection speed with mini chart
JavaScript
1
star
62

artplayer-ie-tester

Test Artplayer.js in Internet Explorer
JavaScript
1
star
63

alioss-watcher

Chrome 扩展 - 阿里云OSS监听器
1
star