mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-27 17:51:20 -08:00
add artplayer-plugin-dash-quality
This commit is contained in:
1 parent
3f399e4b41
commit
f472410a3b
171 files changed
+3241
-2025
No files matched your search
@@ -0,0 +1,10 @@
|
||||
node_modules
|
||||
.DS_Store
|
||||
yarn.lock
|
||||
package-lock.json
|
||||
test
|
||||
coverage
|
||||
.nyc_output
|
||||
.parcel-cache
|
||||
.cache
|
||||
docs
|
||||
@@ -0,0 +1 @@
|
||||
package-lock=false
|
||||
@@ -0,0 +1,15 @@
|
||||
# artplayer-plugin-dash-quality
|
||||
|
||||
Dash quality plugin for ArtPlayer
|
||||
|
||||
## Demo
|
||||
|
||||
[https://artplayer.org](https://artplayer.org/?libs=https://cdnjs.cloudflare.com/ajax/libs/dashjs/4.5.2/dash.all.min.js%0A./uncompiled/artplayer-plugin-dash-quality/index.js&example=dash.quality)
|
||||
|
||||
## Usage
|
||||
|
||||
[https://artplayer.org/document/en/Plugins/dash-quality](https://artplayer.org/document/en/Plugins/dash-quality)
|
||||
|
||||
## License
|
||||
|
||||
MIT © Harvey Zack
|
||||
@@ -0,0 +1,7 @@
|
||||
/*!
|
||||
* artplayer-plugin-dash-quality.js v1.0.0
|
||||
* Github: https://github.com/zhw2590582/ArtPlayer
|
||||
* (c) 2017-2023 Harvey Zack
|
||||
* Released under the MIT License.
|
||||
*/
|
||||
!function(e,t,n,o,r){var i="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},a="function"==typeof i.parcelRequire4dc0&&i.parcelRequire4dc0,u=a.cache||{},l="undefined"!=typeof module&&"function"==typeof module.require&&module.require.bind(module);function d(t,n){if(!u[t]){if(!e[t]){var o="function"==typeof i.parcelRequire4dc0&&i.parcelRequire4dc0;if(!n&&o)return o(t,!0);if(a)return a(t,!0);if(l&&"string"==typeof t)return l(t);var r=new Error("Cannot find module '"+t+"'");throw r.code="MODULE_NOT_FOUND",r}f.resolve=function(n){var o=e[t][1][n];return null!=o?o:n},f.cache={};var c=u[t]=new d.Module(t);e[t][0].call(c.exports,f,c,c.exports,this)}return u[t].exports;function f(e){var t=f.resolve(e);return!1===t?{}:d(t)}}d.isParcelRequire=!0,d.Module=function(e){this.id=e,this.bundle=d,this.exports={}},d.modules=e,d.cache=u,d.parent=a,d.register=function(t,n){e[t]=[function(e,t){t.exports=n},{}]},Object.defineProperty(d,"root",{get:function(){return i.parcelRequire4dc0}}),i.parcelRequire4dc0=d;for(var c=0;c<t.length;c++)d(t[c]);var f=d(n);"object"==typeof exports&&"undefined"!=typeof module?module.exports=f:"function"==typeof define&&define.amd&&define((function(){return f}))}({"92dvd":[function(e,t,n){var o=e("@parcel/transformer-js/src/esmodule-helpers.js");o.defineInteropFlag(n);var r=e("bundle-text:./image.svg"),i=o.interopDefault(r);function a(e){return t=>{const{$video:n}=t.template,{errorHandle:o}=t.constructor.utils;return t.on("ready",(function(){const r=t.dash||window.dash;o(r&&r.getVideoElement()===n,'Cannot find instance of Dash from "art.dash" or "window.dash"');const a=e.auto||"Auto",u=e.title||"Quality",l=r.getBitrateInfoListFor("video"),d=r.getQualityFor("video"),c=e.getResolution||(e=>(e.height||"Unknown ")+"P"),f=r.getSettings(),s=l[d],p=f?.streaming?.abr?.autoSwitchBitrate?.video?a:c(s),h={streaming:{abr:{autoSwitchBitrate:{}}}};e.control&&t.controls.add({name:"dash-quality",position:"right",html:p,style:{padding:"0 10px"},selector:l.map(((e,t)=>({html:c(e),level:t,default:s===e}))),onSelect:e=>(h.streaming.abr.autoSwitchBitrate.video=!1,r.updateSettings(h),r.setQualityFor("video",e.level,!0),e.html)}),e.setting&&t.setting.add({name:"dash-quality",tooltip:p,html:u,icon:i.default,width:200,selector:l.map(((e,t)=>({html:c(e),level:t,default:s===e}))),onSelect:function(e){return h.streaming.abr.autoSwitchBitrate.video=!1,r.updateSettings(h),r.setQualityFor("video",e.level,!0),e.html}})})),{name:"artplayerPluginDashQuality"}}}n.default=a,a.env="production",a.version="1.0.0",a.build="2023-02-18 13:05:59","undefined"!=typeof window&&(window.artplayerPluginDashQuality=a)},{"bundle-text:./image.svg":"kcayM","@parcel/transformer-js/src/esmodule-helpers.js":"9pCYc"}],kcayM:[function(e,t,n){t.exports='<svg class="icon" viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="24" height="24"><path d="M870.4 176H153.6c-49.472 0-89.6 40.128-89.6 89.6v492.736c0 49.472 40.128 89.6 89.6 89.6h716.8c49.472 0 89.6-40.128 89.6-89.6V265.6c0-49.472-40.128-89.6-89.6-89.6zm0 492.8h-44.8s-29.696-65.792-89.6-89.6-134.4 89.6-134.4 89.6-66.56-71.808-134.4-224S153.6 624 153.6 624V265.6h716.8v403.2zM668.8 489.6c37.056 0 67.2-30.144 67.2-67.264 0-37.056-30.144-67.2-67.2-67.2-37.12.064-67.2 30.208-67.2 67.264 0 37.12 30.08 67.2 67.2 67.2z" fill="#fff"/></svg>'},{}],"9pCYc":[function(e,t,n){n.interopDefault=function(e){return e&&e.__esModule?e:{default:e}},n.defineInteropFlag=function(e){Object.defineProperty(e,"__esModule",{value:!0})},n.exportAll=function(e,t){return Object.keys(e).forEach((function(n){"default"===n||"__esModule"===n||t.hasOwnProperty(n)||Object.defineProperty(t,n,{enumerable:!0,get:function(){return e[n]}})})),t},n.export=function(e,t,n){Object.defineProperty(e,t,{enumerable:!0,get:n})}},{}]},["92dvd"],"92dvd");
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
/*!
|
||||
* artplayer-plugin-dash-quality.js v1.0.0
|
||||
* Github: https://github.com/zhw2590582/ArtPlayer
|
||||
* (c) 2017-2023 Harvey Zack
|
||||
* Released under the MIT License.
|
||||
*/
|
||||
!function(e,t,n,r,o){var i="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},u="function"==typeof i.parcelRequire4dc0&&i.parcelRequire4dc0,l=u.cache||{},a="undefined"!=typeof module&&"function"==typeof module.require&&module.require.bind(module);function d(t,n){if(!l[t]){if(!e[t]){var r="function"==typeof i.parcelRequire4dc0&&i.parcelRequire4dc0;if(!n&&r)return r(t,!0);if(u)return u(t,!0);if(a&&"string"==typeof t)return a(t);var o=new Error("Cannot find module '"+t+"'");throw o.code="MODULE_NOT_FOUND",o}c.resolve=function(n){var r=e[t][1][n];return null!=r?r:n},c.cache={};var f=l[t]=new d.Module(t);e[t][0].call(f.exports,c,f,f.exports,this)}return l[t].exports;function c(e){var t=c.resolve(e);return!1===t?{}:d(t)}}d.isParcelRequire=!0,d.Module=function(e){this.id=e,this.bundle=d,this.exports={}},d.modules=e,d.cache=l,d.parent=u,d.register=function(t,n){e[t]=[function(e,t){t.exports=n},{}]},Object.defineProperty(d,"root",{get:function(){return i.parcelRequire4dc0}}),i.parcelRequire4dc0=d;for(var f=0;f<t.length;f++)d(t[f]);var c=d(n);"object"==typeof exports&&"undefined"!=typeof module?module.exports=c:"function"==typeof define&&define.amd&&define((function(){return c}))}({"1XYOW":[function(e,t,n){var r=e("@parcel/transformer-js/src/esmodule-helpers.js");r.defineInteropFlag(n);var o=e("bundle-text:./image.svg"),i=r.interopDefault(o);function u(e){return function(t){var n=t.template.$video,r=t.constructor.utils.errorHandle;return t.on("ready",(function(){var o,u,l,a=t.dash||window.dash;r(a&&a.getVideoElement()===n,'Cannot find instance of Dash from "art.dash" or "window.dash"');var d=e.auto||"Auto",f=e.title||"Quality",c=a.getBitrateInfoListFor("video"),s=a.getQualityFor("video"),p=e.getResolution||function(e){return(e.height||"Unknown ")+"P"},h=a.getSettings(),v=c[s],g=(null==h||null===(o=h.streaming)||void 0===o||null===(u=o.abr)||void 0===u||null===(l=u.autoSwitchBitrate)||void 0===l?void 0:l.video)?d:p(v),m={streaming:{abr:{autoSwitchBitrate:{}}}};e.control&&t.controls.add({name:"dash-quality",position:"right",html:g,style:{padding:"0 10px"},selector:c.map((function(e,t){return{html:p(e),level:t,default:v===e}})),onSelect:function(e){return m.streaming.abr.autoSwitchBitrate.video=!1,a.updateSettings(m),a.setQualityFor("video",e.level,!0),e.html}}),e.setting&&t.setting.add({name:"dash-quality",tooltip:g,html:f,icon:i.default,width:200,selector:c.map((function(e,t){return{html:p(e),level:t,default:v===e}})),onSelect:function(e){return m.streaming.abr.autoSwitchBitrate.video=!1,a.updateSettings(m),a.setQualityFor("video",e.level,!0),e.html}})})),{name:"artplayerPluginDashQuality"}}}n.default=u,u.env="production",u.version="1.0.0",u.build="2023-02-18 13:06:00","undefined"!=typeof window&&(window.artplayerPluginDashQuality=u)},{"bundle-text:./image.svg":"48QdU","@parcel/transformer-js/src/esmodule-helpers.js":"47PTV"}],"48QdU":[function(e,t,n){t.exports='<svg class="icon" viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="24" height="24"><path d="M870.4 176H153.6c-49.472 0-89.6 40.128-89.6 89.6v492.736c0 49.472 40.128 89.6 89.6 89.6h716.8c49.472 0 89.6-40.128 89.6-89.6V265.6c0-49.472-40.128-89.6-89.6-89.6zm0 492.8h-44.8s-29.696-65.792-89.6-89.6-134.4 89.6-134.4 89.6-66.56-71.808-134.4-224S153.6 624 153.6 624V265.6h716.8v403.2zM668.8 489.6c37.056 0 67.2-30.144 67.2-67.264 0-37.056-30.144-67.2-67.2-67.2-37.12.064-67.2 30.208-67.2 67.264 0 37.12 30.08 67.2 67.2 67.2z" fill="#fff"/></svg>'},{}],"47PTV":[function(e,t,n){n.interopDefault=function(e){return e&&e.__esModule?e:{default:e}},n.defineInteropFlag=function(e){Object.defineProperty(e,"__esModule",{value:!0})},n.exportAll=function(e,t){return Object.keys(e).forEach((function(n){"default"===n||"__esModule"===n||t.hasOwnProperty(n)||Object.defineProperty(t,n,{enumerable:!0,get:function(){return e[n]}})})),t},n.export=function(e,t,n){Object.defineProperty(e,t,{enumerable:!0,get:n})}},{}]},["1XYOW"],"1XYOW");
|
||||
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"license": "MIT",
|
||||
"version": "1.0.0",
|
||||
"name": "artplayer-plugin-dash-quality",
|
||||
"types": "types/artplayer-plugin-dash-quality.d.ts",
|
||||
"description": "Iframe plugin for ArtPlayer",
|
||||
"main": "dist/artplayer-plugin-dash-quality.js",
|
||||
"legacy": "dist/artplayer-plugin-dash-quality.legacy.js",
|
||||
"author": "Harvey Zack <laozhaochaguan@gmail.com>",
|
||||
"browserslist": "> 0.5%, last 2 versions, not dead",
|
||||
"homepage": "https://artplayer.org",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/zhw2590582/ArtPlayer.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/zhw2590582/ArtPlayer/issues"
|
||||
},
|
||||
"keywords": [
|
||||
"html5",
|
||||
"video",
|
||||
"player"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" standalone="no"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<svg t="1666857514489" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2580" xmlns:xlink="http://www.w3.org/1999/xlink" width="24" height="24"><path d="M870.4 176 153.6 176C104.128 176 64 216.128 64 265.6l0 492.736c0 49.472 40.128 89.6 89.6 89.6L870.4 847.936c49.472 0 89.6-40.128 89.6-89.6L960 265.6C960 216.128 919.872 176 870.4 176zM870.4 668.8 825.6 668.8c0 0-29.696-65.792-89.6-89.6s-134.4 89.6-134.4 89.6S535.04 596.992 467.2 444.8C399.36 292.608 153.6 624 153.6 624l0-358.4L870.4 265.6 870.4 668.8zM668.8 489.6c37.056 0 67.2-30.144 67.2-67.264 0-37.056-30.144-67.2-67.2-67.2C631.68 355.2 601.6 385.344 601.6 422.4 601.6 459.52 631.68 489.6 668.8 489.6z" p-id="2581" fill="#ffffff"></path>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 883 B |
@@ -0,0 +1,91 @@
|
||||
import image from 'bundle-text:./image.svg';
|
||||
|
||||
export default function artplayerPluginDashQuality(option) {
|
||||
return (art) => {
|
||||
const { $video } = art.template;
|
||||
const { errorHandle } = art.constructor.utils;
|
||||
|
||||
function update() {
|
||||
const dash = art.dash || window.dash;
|
||||
errorHandle(
|
||||
dash && dash.getVideoElement() === $video,
|
||||
'Cannot find instance of Dash from "art.dash" or "window.dash"',
|
||||
);
|
||||
const auto = option.auto || 'Auto';
|
||||
const title = option.title || 'Quality';
|
||||
const levels = dash.getBitrateInfoListFor('video');
|
||||
const currentLevel = dash.getQualityFor('video');
|
||||
const getResolution = option.getResolution || ((level) => (level.height || 'Unknown ') + 'P');
|
||||
const settings = dash.getSettings();
|
||||
const defaultLevel = levels[currentLevel];
|
||||
const defaultHtml = settings?.streaming?.abr?.autoSwitchBitrate?.video ? auto : getResolution(defaultLevel);
|
||||
|
||||
const cfg = {
|
||||
streaming: {
|
||||
abr: {
|
||||
autoSwitchBitrate: {},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
if (option.control) {
|
||||
art.controls.add({
|
||||
name: 'dash-quality',
|
||||
position: 'right',
|
||||
html: defaultHtml,
|
||||
style: { padding: '0 10px' },
|
||||
selector: levels.map((item, index) => {
|
||||
return {
|
||||
html: getResolution(item),
|
||||
level: index,
|
||||
default: defaultLevel === item,
|
||||
};
|
||||
}),
|
||||
onSelect(item) {
|
||||
cfg.streaming.abr.autoSwitchBitrate['video'] = false;
|
||||
dash.updateSettings(cfg);
|
||||
dash.setQualityFor('video', item.level, true);
|
||||
return item.html;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
if (option.setting) {
|
||||
art.setting.add({
|
||||
name: 'dash-quality',
|
||||
tooltip: defaultHtml,
|
||||
html: title,
|
||||
icon: image,
|
||||
width: 200,
|
||||
selector: levels.map((item, index) => {
|
||||
return {
|
||||
html: getResolution(item),
|
||||
level: index,
|
||||
default: defaultLevel === item,
|
||||
};
|
||||
}),
|
||||
onSelect: function (item) {
|
||||
cfg.streaming.abr.autoSwitchBitrate['video'] = false;
|
||||
dash.updateSettings(cfg);
|
||||
dash.setQualityFor('video', item.level, true);
|
||||
return item.html;
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
art.on('ready', update);
|
||||
|
||||
return {
|
||||
name: 'artplayerPluginDashQuality',
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
artplayerPluginDashQuality.env = process.env.NODE_ENV;
|
||||
artplayerPluginDashQuality.version = process.env.APP_VER;
|
||||
artplayerPluginDashQuality.build = process.env.BUILD_DATE;
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
window['artplayerPluginDashQuality'] = artplayerPluginDashQuality;
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
import type Artplayer from 'artplayer';
|
||||
|
||||
export = artplayerPluginDashQuality;
|
||||
export as namespace artplayerPluginDashQuality;
|
||||
|
||||
declare const artplayerPluginDashQuality: (option: {
|
||||
control?: boolean;
|
||||
setting?: boolean;
|
||||
title?: string;
|
||||
auto?: string;
|
||||
getResolution?(level: any): String;
|
||||
}) => (art: Artplayer) => {
|
||||
name: 'artplayerPluginDashQuality';
|
||||
};
|
||||
Reference in new issue
Block a user