Skip to content

Commit

Permalink
feat: pluginOptions flv mediaDataSource and config
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed May 23, 2020
1 parent 2ed6ef8 commit af4d697
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
8 changes: 7 additions & 1 deletion docs/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,13 @@ const dp = new DPlayer({
},
pluginOptions: {
flv: {
// flv config
// refer to https://github.com/bilibili/flv.js/blob/master/docs/api.md#flvjscreateplayer
mediaDataSource: {
// mediaDataSource config
},
config: {
// config
},
},
},
});
Expand Down
8 changes: 7 additions & 1 deletion docs/zh/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,13 @@ const dp = new DPlayer({
},
pluginOptions: {
flv: {
// flv config
// refer to https://github.com/bilibili/flv.js/blob/master/docs/api.md#flvjscreateplayer
mediaDataSource: {
// mediaDataSource config
},
config: {
// config
},
},
},
});
Expand Down
2 changes: 1 addition & 1 deletion src/js/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default (options) => {
video: {},
contextmenu: [],
mutex: true,
pluginOptions: { hls: {}, flvjs: {}, dash: {}, webtorrent: {} },
pluginOptions: { hls: {}, flv: {}, dash: {}, webtorrent: {} },
};
for (const defaultKey in defaultOption) {
if (defaultOption.hasOwnProperty(defaultKey) && !options.hasOwnProperty(defaultKey)) {
Expand Down
19 changes: 9 additions & 10 deletions src/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,11 +370,13 @@ class DPlayer {
case 'flv':
if (window.flvjs) {
if (window.flvjs.isSupported()) {
const options = Object.assign(this.options.pluginOptions.flvjs, {
type: 'flv',
url: video.src,
});
const flvPlayer = window.flvjs.createPlayer(options);
const flvPlayer = window.flvjs.createPlayer(
Object.assign(this.options.pluginOptions.flv.mediaDataSource || {}, {
type: 'flv',
url: video.src,
}),
this.options.pluginOptions.flv.config
);
this.plugins.flvjs = flvPlayer;
flvPlayer.attachMediaElement(video);
flvPlayer.load();
Expand All @@ -395,10 +397,7 @@ class DPlayer {
// https://github.com/Dash-Industry-Forum/dash.js
case 'dash':
if (window.dashjs) {
const dashjsPlayer = window.dashjs
.MediaPlayer()
.create()
.initialize(video, video.src, false);
const dashjsPlayer = window.dashjs.MediaPlayer().create().initialize(video, video.src, false);
const options = this.options.pluginOptions.dash;
dashjsPlayer.updateSettings(options);
this.plugins.dash = dashjsPlayer;
Expand Down Expand Up @@ -427,7 +426,7 @@ class DPlayer {
const file = torrent.files.find((file) => file.name.endsWith('.mp4'));
file.renderTo(this.video, {
autoplay: this.options.autoplay,
controls: false
controls: false,
});
});
this.events.on('destroy', () => {
Expand Down

0 comments on commit af4d697

Please sign in to comment.