201 Star 683 Fork 172

Pear / PearPlayer.js

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
get-started.md 2.76 KB
一键复制 编辑 原始数据 按行查看 历史
Damon Qin 提交于 2017-11-29 16:40 . Fix markdown tabs ( 4 => 2 )

Get Started with PearPlayer

PearPlayer is a multi-source and multi-protocol P2P streaming player that works in the browser. It's easy to get started!

Import

Script

Simply include the (pear-player.min.js) script on your page and use require():

<script src="pear-player.min.js"></script>

Browserify

To install PearPlayer for use in the browser with require('PearPlayer'), run:

npm install pearplayer --save

Then you can require PearPlayer like this:

var PearPlayer = require('PearPlayer');

Quick Examples

Hook the video and play

var PearPlayer = require('PearPlayer');
var player = new PearPlayer('#pearvideo');

There is a complete example in examples/test.html

Listen to PearPlayer events

var player = new PearPlayer('#pearvideo', {
  //第一个参数为video标签的id或class
  type: 'mp4', //播放视频的类型,目前只能是mp4
  src: 'https://qq.webrtc.win/tv/pear001.mp4', //视频播放的src
  useMonitor: true //是否开启monitor,会稍微影响性能,默认false
});

player.on('exception', onException);
player.on('begin', onBegin);
player.on('progress', onProgress);
player.on('buffersources', onBufferSources); //s: server   n: node  d: data channel  b: browser
player.on('done', onDone);

function onBegin(fileLength, chunks) {
  console.log('start downloading buffer by first aid, file length is:' + fileLength + ' total chunks:' + chunks);
}

function onProgress(downloaded) {
  console.log('Progress: ' + (downloaded * 100).toFixed(1) + '%');
}

function onDone() {
  console.log('finished downloading buffer by first aid');
}

function onException(exception) {
  var errCode = exception.errCode;
  switch (errCode) {
    case 1:
      //当前浏览器不支持WebRTC
      console.log(exception.errMsg);
      break;
  }
}
function onBufferSources(bufferSources) {
  //s: server   n: node  d: data channel  b: browser
  console.log('Current Buffer Sources:' + bufferSources);
}

Build

PearPlayer works great with browserify, which lets you use node.js style require() to organize your browser code, and load packages installed by npm.

npm install -g browserify

Install dependencies:

npm install

To get a normal size bundle,use:

npm run build

To get a compressed bundle,use:

npm run build
npm run gulp

More Documentation

Check out the API Documentation and FAQ for more details.

JavaScript
1
https://gitee.com/PearInc/PearPlayer.js.git
git@gitee.com:PearInc/PearPlayer.js.git
PearInc
PearPlayer.js
PearPlayer.js
master

搜索帮助