diff --git a/docs/docs/README.md b/docs/docs/README.md index 308a4d962..2b6b9fac7 100644 --- a/docs/docs/README.md +++ b/docs/docs/README.md @@ -90,6 +90,49 @@ var art = new Artplayer({ }); ``` +## type + +- Type: `String` +- Default: `''` + +Specify the format for the `url`, use with `customType` + +[Run Code](/) + +```js +var url = 'https://blog.zhw-island.com/assets-cdn'; +var art = new Artplayer({ + container: '.artplayer-app', + url: url + '/video/one-more-time-one-more-chance-480p.flv' + type: 'flv' +}); +``` + +## customType + +- Type: `Object` +- Default: `{}` + +Customize when loading third-party libraries + +[Run Code](/) + +```js +var url = 'https://blog.zhw-island.com/assets-cdn'; +var art = new Artplayer({ + container: '.artplayer-app', + url: url + '/video/one-more-time-one-more-chance-480p.flv' + type: 'flv', + customType: { + flv: function(video, url, art) { + // video: The video element + // url: The video url + // art: The Artplayer instance + } + } +}); +``` + ## poster - Type: `String` @@ -915,6 +958,117 @@ var art = new Artplayer({ > TODO... +# Third-party libraries + +## flv.js + +- HomePage: [https://github.com/Bilibili/flv.js](https://github.com/Bilibili/flv.js) + +[Run Code](/lib=https://cdn.bootcss.com/flv.js/1.4.2/flv.js) + +```js +var url = 'https://blog.zhw-island.com/assets-cdn'; +var art = new Artplayer({ + container: '.artplayer-app', + url: url + '/video/one-more-time-one-more-chance-480p.flv', + customType: { + flv: function(video, url) { + const flvPlayer = flvjs.createPlayer({ + type: 'flv', + url: url, + }); + flvPlayer.attachMediaElement(video); + flvPlayer.load(); + }, + }, +}); +``` + +## hls.js + +- HomePage: [https://github.com/video-dev/hls.js](https://github.com/video-dev/hls.js) + +[Run Code](/lib=https://cdn.bootcss.com/hls.js/0.10.1/hls.js) + +```js +var art = new Artplayer({ + container: '.artplayer-app', + url: 'https://video-dev.github.io/streams/x36xhzz/x36xhzz.m3u8', + customType: { + m3u8: function(video, url) { + var hls = new Hls(); + hls.loadSource(url); + hls.attachMedia(video); + }, + }, +}); +``` + +## dash.js + +- HomePage: [https://github.com/Dash-Industry-Forum/dash.js](https://github.com/Dash-Industry-Forum/dash.js) + +[Run Code](/lib=https://cdn.bootcss.com/dashjs/2.9.2/dash.all.min.js) + +```js +var art = new Artplayer({ + container: '.artplayer-app', + url: 'https://dash.akamaized.net/envivio/EnvivioDash3/manifest.mpd', + customType: { + mpd: function(video, url) { + var player = dashjs.MediaPlayer().create(); + player.initialize(video, url, true); + }, + }, +}); +``` + +## shaka-player + +- HomePage: [https://github.com/google/shaka-player](https://github.com/google/shaka-player) + +[Run Code](/lib=https://cdn.bootcss.com/shaka-player/2.5.0-beta/shaka-player.compiled.js) + +```js +var art = new Artplayer({ + container: '.artplayer-app', + url: '//storage.googleapis.com/shaka-demo-assets/angel-one/dash.mpd', + customType: { + mpd: function(video, url) { + shaka.polyfill.installAll(); + var player = new shaka.Player(video); + player.load(url); + }, + }, +}); +``` + +## webtorrent + +- HomePage: [https://github.com/webtorrent/webtorrent](https://github.com/webtorrent/webtorrent) + +[Run Code](/lib=https://cdn.bootcss.com/webtorrent/0.102.4/webtorrent.min.js) + +```js +var art = new Artplayer({ + container: '.artplayer-app', + url: 'magnet:?xt=urn:btih:6a9759bffd5c0af65319979fb7832189f4f3c35d&dn=sintel.mp4&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&tr=wss%3A%2F%2Ftracker.webtorrent.io&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2Fsintel-1024-surround.mp4', + type: 'torrent', + customType: { + torrent: function (video, url, art) { + var client = new WebTorrent(); + art.loading.show(); + client.add(url, function (torrent) { + var file = torrent.files[0]; + file.renderTo(video, { + autoplay: true + }) + }) + }, + }, +}); +``` + # Issue > TODO... diff --git a/docs/docs/runCode.js b/docs/docs/runCode.js index 069fba6f2..03ac24661 100644 --- a/docs/docs/runCode.js +++ b/docs/docs/runCode.js @@ -12,10 +12,16 @@ window.runCode = function(hook) { codeElement.tagName === 'PRE' && codeElement.dataset.lang === 'js' ) { - var code = window.encodeURIComponent(codeElement.innerText); - window.open( - 'https://artplayer.org/lab/?code=' + code - ); + var libs = item.href.split('/lib=')[1]; + var code = encodeURIComponent(codeElement.innerText); + var url = 'https://artplayer.org/lab/?'; + if (libs) { + url += 'libs=' + libs + '&'; + } + if (code) { + url += 'code=' + code; + } + window.open(url); } }); }); diff --git a/docs/lab/css/common.css b/docs/lab/css/common.css index 23b4c216a..482a6822d 100644 --- a/docs/lab/css/common.css +++ b/docs/lab/css/common.css @@ -31,13 +31,13 @@ html, body { box-sizing: border-box; } -.part-left .header .left { +.part-left .header .links { display: flex; align-items: center; flex: 1; } -.part-left .header .left .logo { +.part-left .header .links a { padding-right: 30px; } diff --git a/docs/lab/dash.html b/docs/lab/dash.html deleted file mode 100644 index 07769d566..000000000 --- a/docs/lab/dash.html +++ /dev/null @@ -1,60 +0,0 @@ - - - - - ArtPlayer.js Lab - - - - - - - - - - - - - - -
-
-
- - -
-
-
-
-
-
-
-
-
-
- - - - - - - - - - - \ No newline at end of file diff --git a/docs/lab/flv.html b/docs/lab/flv.html deleted file mode 100644 index 2daa947f0..000000000 --- a/docs/lab/flv.html +++ /dev/null @@ -1,60 +0,0 @@ - - - - - ArtPlayer.js Lab - - - - - - - - - - - - - - -
-
-
- - -
-
-
-
-
-
-
-
-
-
- - - - - - - - - - - \ No newline at end of file diff --git a/docs/lab/hls.html b/docs/lab/hls.html deleted file mode 100644 index e87b47fd3..000000000 --- a/docs/lab/hls.html +++ /dev/null @@ -1,60 +0,0 @@ - - - - - ArtPlayer.js Lab - - - - - - - - - - - - - - -
-
-
- - -
-
-
-
-
-
-
-
-
-
- - - - - - - - - - - \ No newline at end of file diff --git a/docs/lab/index.html b/docs/lab/index.html index f8bbe0161..824d33d04 100644 --- a/docs/lab/index.html +++ b/docs/lab/index.html @@ -20,14 +20,14 @@
diff --git a/docs/lab/js/common.js b/docs/lab/js/common.js index 884d9eaab..d2df4cc53 100644 --- a/docs/lab/js/common.js +++ b/docs/lab/js/common.js @@ -1,4 +1,4 @@ -(function(win) { +(function() { var $code = document.querySelector('.code'); var $run = document.querySelector('.run'); var $lib = document.querySelector('.lib'); @@ -57,23 +57,33 @@ script.onload = function() { resolve(url); }; + script.onerror = function() { + reject(new Error('Loading script failed:' + url)); + }; document.querySelector('head').appendChild(script); }); } function loadStyle(url) { - return new Promise(function(resolve) { - var style = document.createElement('style'); - style.type = 'text/css'; - style.src = url; - document.querySelector('head').appendChild(style); - resolve(url); + return new Promise(function(resolve, reject) { + var link = document.createElement('link'); + link.rel = 'stylesheet'; + link.href = url; + link.onload = function() { + resolve(url); + }; + link.onerror = function() { + reject(new Error('Loading style failed:' + url)); + }; + document.querySelector('head').appendChild(link); }); } - function loadLib(libs = defaultLib) { + function loadLib(libs) { var libPromise = []; - libs.split(',') + var libsDecode = decodeURIComponent(libs || defaultLib); + libsDecode + .split(/\r?\n/) .filter(function(url) { return !loaddLib.includes(url); }) @@ -85,45 +95,27 @@ libPromise.push(loadStyle(url)); } }); - $lib.value = decodeURIComponent(libs); + $lib.value = libsDecode; return Promise.all(libPromise); } function loadCode(code) { - return new Promise(function(resolve, reject) { - if (code) { - mirror.setValue(decodeURIComponent(code).trim()); - runCode(); - resolve(code); - } else { - fetch('./js/example.js') - .then(response => { - return response.text(); - }) - .then(text => { - mirror.setValue(text); - runCode(); - resolve(text); - }) - .catch(err => { - console.error(err.message); - }); - } - }); - } - - function initApp() { - const { code, libs } = getURLParameters(window.location.href); - loadLib(libs) - .then(function(result) { - loaddLib = loaddLib.concat(result); - loadCode(code).then(() => { - console.info('App initialization completed'); + if (code) { + mirror.setValue(decodeURIComponent(code).trim()); + runCode(); + } else { + fetch('./js/example.js') + .then(response => { + return response.text(); + }) + .then(text => { + mirror.setValue(text); + runCode(); + }) + .catch(err => { + console.error(err.message); }); - }) - .catch(err => { - console.error(err.message); - }); + } } function runCode() { @@ -133,19 +125,32 @@ var code = mirror.getValue(); eval(code); initArt(Artplayer.instances[0]); + console.info('Player initialization completed'); + } + + function initApp() { + const { code, libs } = getURLParameters(window.location.href); + loadLib(libs) + .then(function(result) { + loaddLib = loaddLib.concat(result); + loadCode(code); + }) + .catch(err => { + console.error(err.message); + }); } $run.addEventListener('click', function(e) { - runCode(); const libs = encodeURIComponent($lib.value); const code = encodeURIComponent(mirror.getValue()); const url = window.location.origin + window.location.pathname + '?libs=' + libs + '&code=' + code; history.pushState(null, null, url); + initApp(); }); - win.addEventListener('error', err => { + window.addEventListener('error', err => { console.error(err.message); }); initApp(); -})(window); +})(); diff --git a/docs/lab/js/dash.js b/docs/lab/js/dash.js deleted file mode 100644 index d137feb3e..000000000 --- a/docs/lab/js/dash.js +++ /dev/null @@ -1,10 +0,0 @@ -var art = new Artplayer({ - container: '.artplayer-app', - url: 'https://dash.akamaized.net/envivio/EnvivioDash3/manifest.mpd', - customType: { - mpd: function(video, url) { - var player = dashjs.MediaPlayer().create(); - player.initialize(video, url, true); - }, - }, -}); \ No newline at end of file diff --git a/docs/lab/js/flv.js b/docs/lab/js/flv.js deleted file mode 100644 index 0af364276..000000000 --- a/docs/lab/js/flv.js +++ /dev/null @@ -1,15 +0,0 @@ -var url = 'https://blog.zhw-island.com/assets-cdn'; -var art = new Artplayer({ - container: '.artplayer-app', - url: url + '/video/one-more-time-one-more-chance-480p.flv', - customType: { - flv: function(video, url) { - const flvPlayer = flvjs.createPlayer({ - type: 'flv', - url: url, - }); - flvPlayer.attachMediaElement(video); - flvPlayer.load(); - }, - }, -}); \ No newline at end of file diff --git a/docs/lab/js/hls.js b/docs/lab/js/hls.js deleted file mode 100644 index 181fd420d..000000000 --- a/docs/lab/js/hls.js +++ /dev/null @@ -1,11 +0,0 @@ -var art = new Artplayer({ - container: '.artplayer-app', - url: 'https://video-dev.github.io/streams/x36xhzz/x36xhzz.m3u8', - customType: { - m3u8: function(video, url) { - var hls = new Hls(); - hls.loadSource(url); - hls.attachMedia(video); - }, - }, -}); \ No newline at end of file diff --git a/docs/lab/js/shaka.js b/docs/lab/js/shaka.js deleted file mode 100644 index dd8d0a295..000000000 --- a/docs/lab/js/shaka.js +++ /dev/null @@ -1,11 +0,0 @@ -var art = new Artplayer({ - container: '.artplayer-app', - url: '//storage.googleapis.com/shaka-demo-assets/angel-one/dash.mpd', - customType: { - mpd: function(video, url) { - shaka.polyfill.installAll(); - var player = new shaka.Player(video); - player.load(url); - }, - }, -}); \ No newline at end of file diff --git a/docs/lab/js/webtorrent.js b/docs/lab/js/webtorrent.js deleted file mode 100644 index 2fbacd5a9..000000000 --- a/docs/lab/js/webtorrent.js +++ /dev/null @@ -1,17 +0,0 @@ -var art = new Artplayer({ - container: '.artplayer-app', - url: 'magnet:?xt=urn:btih:6a9759bffd5c0af65319979fb7832189f4f3c35d&dn=sintel.mp4&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&tr=wss%3A%2F%2Ftracker.webtorrent.io&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2Fsintel-1024-surround.mp4', - type: 'torrent', - customType: { - torrent: function (video, url, art) { - var client = new WebTorrent(); - art.loading.show(); - client.add(url, function (torrent) { - var file = torrent.files[0]; - file.renderTo(video, { - autoplay: true - }) - }) - }, - }, -}); diff --git a/docs/lab/shaka.html b/docs/lab/shaka.html deleted file mode 100644 index ffd8b2bf2..000000000 --- a/docs/lab/shaka.html +++ /dev/null @@ -1,60 +0,0 @@ - - - - - ArtPlayer.js Lab - - - - - - - - - - - - - - -
-
-
- - -
-
-
-
-
-
-
-
-
-
- - - - - - - - - - - \ No newline at end of file diff --git a/docs/lab/webtorrent.html b/docs/lab/webtorrent.html deleted file mode 100644 index 6ce01a3a5..000000000 --- a/docs/lab/webtorrent.html +++ /dev/null @@ -1,60 +0,0 @@ - - - - - ArtPlayer.js Lab - - - - - - - - - - - - - - -
-
-
- - -
-
-
-
-
-
-
-
-
-
- - - - - - - - - - - \ No newline at end of file