소스 검색

feat: pluginOptions flv mediaDataSource and config

DIYgod 5 년 전
부모
커밋
af4d697b19
4개의 변경된 파일24개의 추가작업 그리고 13개의 파일을 삭제
  1. 7 1
      docs/guide.md
  2. 7 1
      docs/zh/guide.md
  3. 1 1
      src/js/options.js
  4. 9 10
      src/js/player.js

+ 7 - 1
docs/guide.md

@@ -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
+            },
         },
     },
 });

+ 7 - 1
docs/zh/guide.md

@@ -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
+            },
         },
     },
 });

+ 1 - 1
src/js/options.js

@@ -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)) {

+ 9 - 10
src/js/player.js

@@ -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();
@@ -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;
@@ -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', () => {