Skip to content

Commit

Permalink
Merge branch 'flvjs-option'
Browse files Browse the repository at this point in the history
  • Loading branch information
hexray-newbee committed Dec 13, 2017
2 parents 7a20502 + 5c89bf1 commit 3bf1d97
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 53 deletions.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": [ "env" ]
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
es5/
32 changes: 32 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
sudo: false
dist: trusty
language: node_js
node_js:
- 'node'
before_script:

# Check if the current version is equal to the major version for the env.
- 'export IS_INSTALLED="$(npm list video.js | grep "video.js@$VJS")"'

# We have to add semicolons to the end of each line in the if as Travis runs
# this all on one line.
- 'if [ -z "$IS_INSTALLED" ]; then
echo "INSTALLING video.js@>=$VJS.0.0-RC.0 <$(($VJS+1)).0.0";
npm i "video.js@>=$VJS.0.0-RC.0 <\$(($VJS+1)).0.0";
else
echo "video.js@$VJS ALREADY INSTALLED";
fi'
- export CHROME_BIN=/usr/bin/google-chrome
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
env:
- VJS=5
- VJS=6
addons:
firefox: latest
apt:
sources:
- google-chrome
packages:
- google-chrome-stable

62 changes: 22 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Video.js tech to use [flv.js](https://github.com/Bilibili/flv.js) for FLV playba

Check out the flv.js docs for details on its capabilities, browser support etc. Note that you need [CORS headers](https://github.com/Bilibili/flv.js/blob/master/docs/cors.md) if your video is being hosted at a different origin.

[Example](https://github.com/mister-ben/videojs-flvjs)
[Example](https://mister-ben.github.io/videojs-flvjs/)

## Installation

Expand All @@ -14,54 +14,36 @@ npm install --save videojs-flvjs

## Usage

To include videojs-flvjs on your website or web application, use any of the following methods.

### `<script>` Tag

This is the simplest case. Get the script in whatever way you prefer and include the plugin _after_ you include [video.js][videojs], so that the `videojs` global is available. You also need to include [flv.js](https://github.com/Bilibili/flv.js).
You need to include [flv.js](https://github.com/Bilibili/flv.js) itself.

```html
<!-- Video.js -->
<link href="//path/to/video-js.css" rel="stylesheet">
<script src="//path/to/video.min.js"></script>
<script src="//path/to/flv.js"></script>
<!-- flv.js -->
<script src="//path/to/flv.min.js"></script>
<!-- videojs-flvjs -->
<script src="//path/to/videojs-flvjs.min.js"></script>
<video id="videojs-flvjs-player" class="video-js vjs-default-skin" controls>
<source src="movie.flv" type='video/x-flv'>
</video>
<script>
var player = videojs('my-video', {
techOrder: ['html5', 'flvjs']
// For v5 the tech must be added to the tech order.
// For v6 this is not needed.
videojs('videojs-flvjs-player', {
techOrder: ['html5', 'flvjs'],
flvjs: {
mediaDataSource: {
isLive: true,
cors: true,
withCredentials: false,
},
// config: {},
},
});
</script>
```

You only need to set the techOrder in Video.js version 5. In version 6 techs add themselves to the default techorder. If you are using both the flash and flvjs techs, flvjs should come first.

### Browserify

When using with Browserify, install videojs-flvjs via npm and `require` the plugin as you would any other module.

```js
var videojs = require('video.js');

// The actual plugin function is exported by this module, but it is also
// attached to the `Player.prototype`; so, there is no need to assign it
// to a variable.
require('videojs-flvjs');

var player = videojs('my-video');

player.flvjs();
```

### RequireJS/AMD

When using with RequireJS (or another AMD library), get the script in whatever way you prefer and `require` the plugin as you normally would:

```js
require(['video.js', 'videojs-flvjs'], function(videojs) {
var player = videojs('my-video');

player.flvjs();
});
```

## License

Apache-2.0. Copyright (c) mister-ben
Expand Down
12 changes: 4 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"preversion": "npm test",
"version": "babel-node scripts/version.js",
"postversion": "babel-node scripts/postversion.js",
"prepublish": "npm run build"
"prepare": "npm run build",
"prepush": "npm run lint"
},
"keywords": [
"videojs",
Expand Down Expand Up @@ -86,7 +87,7 @@
"devDependencies": {
"babel-cli": "^6.14.0",
"babel-plugin-transform-object-assign": "^6.8.0",
"babel-preset-es2015": "^6.14.0",
"babel-preset-env": "^1.6.0",
"babelify": "^7.3.0",
"bannerize": "^1.0.2",
"bluebird": "^3.2.2",
Expand All @@ -96,9 +97,9 @@
"bundle-collapser": "^1.2.1",
"chg": "^0.3.2",
"flv.js": "^1.1.0",
"ghooks": "^1.3.2",
"glob": "^6.0.3",
"global": "^4.3.0",
"husky": "^0.14.3",
"karma": "^0.13.19",
"karma-chrome-launcher": "^0.2.2",
"karma-detect-browsers": "^2.0.2",
Expand All @@ -115,10 +116,5 @@
"sinon": "~1.14.0",
"uglify-js": "^2.6.1",
"videojs-standard": "^4.0.0"
},
"config": {
"ghooks": {
"pre-push": "npm run lint"
}
}
}
12 changes: 7 additions & 5 deletions src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ class Flvjs extends Html5 {
this.flvPlayer.detachMediaElement();
this.flvPlayer.destroy();
}
this.flvPlayer = window.flvjs.createPlayer({
type: 'flv',
url: src,
cors: true
});

const mediaDataSource = this.options_.mediaDataSource;
const config = this.options_.config;

mediaDataSource.type = mediaDataSource.type === undefined ? 'flv' : mediaDataSource.type;
mediaDataSource.url = src;
this.flvPlayer = window.flvjs.createPlayer(mediaDataSource, config);
this.flvPlayer.attachMediaElement(this.el_);
this.flvPlayer.load();
}
Expand Down

0 comments on commit 3bf1d97

Please sign in to comment.