mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-08 19:06:15 -08:00
Merge pull request #1058 from acaliskol/fix/unhandled-play-rejection
fix: silence unhandled play() rejections from internal callers
This commit is contained in:
21 files changed
+216
-43
No files matched your search
@@ -23,6 +23,7 @@ jobs:
|
||||
- name: install, lint, build, and test
|
||||
run: |
|
||||
yarn
|
||||
yarn test:playback
|
||||
yarn lint
|
||||
yarn build:all
|
||||
env:
|
||||
|
||||
Vendored
+2
-1
@@ -43,6 +43,7 @@ export interface Utils {
|
||||
loadImg: (url: string, scale?: number) => Promise<HTMLImageElement>
|
||||
|
||||
errorHandle: <T extends boolean>(condition: T, msg: string) => T extends true ? T : never
|
||||
silencePromise: <T>(value: T) => T extends Promise<infer R> ? Promise<R | undefined> : T
|
||||
def: (obj: object, name: string, value: unknown) => void
|
||||
has: (obj: object, name: PropertyKey) => boolean
|
||||
get: (obj: object, name: PropertyKey) => PropertyDescriptor | undefined
|
||||
@@ -1251,7 +1252,7 @@ export default class Artplayer extends Player {
|
||||
|
||||
readonly notice: {
|
||||
timer: number | null
|
||||
get show(): boolean
|
||||
get show(): string | Error | false | ''
|
||||
set show(msg: string | Error | false | '')
|
||||
destroy: () => void
|
||||
}
|
||||
|
||||
@@ -4,4 +4,4 @@
|
||||
* (c) 2017-2026 Harvey Zhao
|
||||
* Released under the MIT License.
|
||||
*/
|
||||
!function(t,e){"object"===typeof exports&&"undefined"!==typeof module?module.exports=e():"function"==typeof define&&define.amd?(t.Artplayer=e(),define(function(){return t.Artplayer})):(t="undefined"!==typeof globalThis?globalThis:t||self).Artplayer=e()}(this,function(){"use strict";function t(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var e,r={exports:{}};var a=(e||(e=1,r.exports=function(){function t(e){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(e)}var e=Object.prototype.toString,r=function(r){if(void 0===r)return"undefined";if(null===r)return"null";var o=t(r);if("boolean"===o)return"boolean";if("string"===o)return"string";if("number"===o)return"number";if("symbol"===o)return"symbol";if("function"===o)return"GeneratorFunction"===a(r)?"generatorfunction":"function";if(function(t){return Array.isArray?Array.isArray(t):t instanceof Array}(r))return"array";if(function(t){return!(!t.constructor||"function"!=typeof t.constructor.isBuffer)&&t.constructor.isBuffer(t)}(r))return"buffer";if(function(t){try{if("number"==typeof t.length&&"function"==typeof t.callee)return!0}catch(e){if(-1!==e.message.indexOf("callee"))return!0}return!1}(r))return"arguments";if(function(t){return t instanceof Date||"function"==typeof t.toDateString&&"function"==typeof t.getDate&&"function"==typeof t.setDate}(r))return"date";if(function(t){return t instanceof Error||"string"==typeof t.message&&t.constructor&&"number"==typeof t.constructor.stackTraceLimit}(r))return"error";if(function(t){return t instanceof RegExp||"string"==typeof t.flags&&"boolean"==typeof t.ignoreCase&&"boolean"==typeof t.multiline&&"boolean"==typeof t.global}(r))return"regexp";switch(a(r)){case"Symbol":return"symbol";case"Promise":return"promise";case"WeakMap":return"weakmap";case"WeakSet":return"weakset";case"Map":return"map";case"Set":return"set";case"Int8Array":return"int8array";case"Uint8Array":return"uint8array";case"Uint8ClampedArray":return"uint8clampedarray";case"Int16Array":return"int16array";case"Uint16Array":return"uint16array";case"Int32Array":return"int32array";case"Uint32Array":return"uint32array";case"Float32Array":return"float32array";case"Float64Array":return"float64array"}if(function(t){return"function"==typeof t.throw&&"function"==typeof t.return&&"function"==typeof t.next}(r))return"generator";switch(o=e.call(r)){case"[object Object]":return"object";case"[object Map Iterator]":return"mapiterator";case"[object Set Iterator]":return"setiterator";case"[object String Iterator]":return"stringiterator";case"[object Array Iterator]":return"arrayiterator"}return o.slice(8,-1).toLowerCase().replace(/\s/g,"")};function a(t){return t.constructor?t.constructor.name:null}function o(t,e){var a=2<arguments.length&&void 0!==arguments[2]?arguments[2]:["option"];return n(t,e,a),i(t,e,a),function(t,e,a){var s=r(e),l=r(t);if("object"===s){if("object"!==l)throw new Error("[Type Error]: '".concat(a.join("."),"' require 'object' type, but got '").concat(l,"'"));Object.keys(e).forEach(function(r){var s=t[r],l=e[r],c=a.slice();c.push(r),n(s,l,c),i(s,l,c),o(s,l,c)})}if("array"===s){if("array"!==l)throw new Error("[Type Error]: '".concat(a.join("."),"' require 'array' type, but got '").concat(l,"'"));t.forEach(function(r,s){var l=t[s],c=e[s]||e[0],d=a.slice();d.push(s),n(l,c,d),i(l,c,d),o(l,c,d)})}}(t,e,a),t}function n(t,e,a){if("string"===r(e)){var o=r(t);if("?"===e[0]&&(e=e.slice(1)+"|undefined"),!(-1<e.indexOf("|")?e.split("|").map(function(t){return t.toLowerCase().trim()}).filter(Boolean).some(function(t){return o===t}):e.toLowerCase().trim()===o))throw new Error("[Type Error]: '".concat(a.join("."),"' require '").concat(e,"' type, but got '").concat(o,"'"))}}function i(t,e,a){if("function"===r(e)){var o=e(t,r(t),a);if(!0!==o){var n=r(o);throw"string"===n?new Error(o):"error"===n?o:new Error("[Validator Error]: The scheme for '".concat(a.join("."),"' validator require return true, but got '").concat(o,"'"))}}}return o.kindOf=r,o}()),r.exports);const o=t(a),n="5.4.1",i={properties:["audioTracks","autoplay","buffered","controller","controls","crossOrigin","currentSrc","currentTime","defaultMuted","defaultPlaybackRate","duration","ended","error","loop","mediaGroup","muted","networkState","paused","playbackRate","played","preload","readyState","seekable","seeking","src","startDate","textTracks","videoTracks","volume"],methods:["addTextTrack","canPlayType","load","play","pause"],events:["abort","canplay","canplaythrough","durationchange","emptied","ended","error","loadeddata","loadedmetadata","loadstart","pause","play","playing","progress","ratechange","seeked","seeking","stalled","suspend","timeupdate","volumechange","waiting"],prototypes:["width","height","videoWidth","videoHeight","poster","webkitDecodedFrameCount","webkitDroppedFrameCount","playsInline","webLine truncated
|
||||
!function(t,e){"object"===typeof exports&&"undefined"!==typeof module?module.exports=e():"function"==typeof define&&define.amd?(t.Artplayer=e(),define(function(){return t.Artplayer})):(t="undefined"!==typeof globalThis?globalThis:t||self).Artplayer=e()}(this,function(){"use strict";function t(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var e,r={exports:{}};var a=(e||(e=1,r.exports=function(){function t(e){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(e)}var e=Object.prototype.toString,r=function(r){if(void 0===r)return"undefined";if(null===r)return"null";var o=t(r);if("boolean"===o)return"boolean";if("string"===o)return"string";if("number"===o)return"number";if("symbol"===o)return"symbol";if("function"===o)return"GeneratorFunction"===a(r)?"generatorfunction":"function";if(function(t){return Array.isArray?Array.isArray(t):t instanceof Array}(r))return"array";if(function(t){return!(!t.constructor||"function"!=typeof t.constructor.isBuffer)&&t.constructor.isBuffer(t)}(r))return"buffer";if(function(t){try{if("number"==typeof t.length&&"function"==typeof t.callee)return!0}catch(e){if(-1!==e.message.indexOf("callee"))return!0}return!1}(r))return"arguments";if(function(t){return t instanceof Date||"function"==typeof t.toDateString&&"function"==typeof t.getDate&&"function"==typeof t.setDate}(r))return"date";if(function(t){return t instanceof Error||"string"==typeof t.message&&t.constructor&&"number"==typeof t.constructor.stackTraceLimit}(r))return"error";if(function(t){return t instanceof RegExp||"string"==typeof t.flags&&"boolean"==typeof t.ignoreCase&&"boolean"==typeof t.multiline&&"boolean"==typeof t.global}(r))return"regexp";switch(a(r)){case"Symbol":return"symbol";case"Promise":return"promise";case"WeakMap":return"weakmap";case"WeakSet":return"weakset";case"Map":return"map";case"Set":return"set";case"Int8Array":return"int8array";case"Uint8Array":return"uint8array";case"Uint8ClampedArray":return"uint8clampedarray";case"Int16Array":return"int16array";case"Uint16Array":return"uint16array";case"Int32Array":return"int32array";case"Uint32Array":return"uint32array";case"Float32Array":return"float32array";case"Float64Array":return"float64array"}if(function(t){return"function"==typeof t.throw&&"function"==typeof t.return&&"function"==typeof t.next}(r))return"generator";switch(o=e.call(r)){case"[object Object]":return"object";case"[object Map Iterator]":return"mapiterator";case"[object Set Iterator]":return"setiterator";case"[object String Iterator]":return"stringiterator";case"[object Array Iterator]":return"arrayiterator"}return o.slice(8,-1).toLowerCase().replace(/\s/g,"")};function a(t){return t.constructor?t.constructor.name:null}function o(t,e){var a=2<arguments.length&&void 0!==arguments[2]?arguments[2]:["option"];return n(t,e,a),i(t,e,a),function(t,e,a){var s=r(e),l=r(t);if("object"===s){if("object"!==l)throw new Error("[Type Error]: '".concat(a.join("."),"' require 'object' type, but got '").concat(l,"'"));Object.keys(e).forEach(function(r){var s=t[r],l=e[r],c=a.slice();c.push(r),n(s,l,c),i(s,l,c),o(s,l,c)})}if("array"===s){if("array"!==l)throw new Error("[Type Error]: '".concat(a.join("."),"' require 'array' type, but got '").concat(l,"'"));t.forEach(function(r,s){var l=t[s],c=e[s]||e[0],d=a.slice();d.push(s),n(l,c,d),i(l,c,d),o(l,c,d)})}}(t,e,a),t}function n(t,e,a){if("string"===r(e)){var o=r(t);if("?"===e[0]&&(e=e.slice(1)+"|undefined"),!(-1<e.indexOf("|")?e.split("|").map(function(t){return t.toLowerCase().trim()}).filter(Boolean).some(function(t){return o===t}):e.toLowerCase().trim()===o))throw new Error("[Type Error]: '".concat(a.join("."),"' require '").concat(e,"' type, but got '").concat(o,"'"))}}function i(t,e,a){if("function"===r(e)){var o=e(t,r(t),a);if(!0!==o){var n=r(o);throw"string"===n?new Error(o):"error"===n?o:new Error("[Validator Error]: The scheme for '".concat(a.join("."),"' validator require return true, but got '").concat(o,"'"))}}}return o.kindOf=r,o}()),r.exports);const o=t(a),n="5.4.1",i={properties:["audioTracks","autoplay","buffered","controller","controls","crossOrigin","currentSrc","currentTime","defaultMuted","defaultPlaybackRate","duration","ended","error","loop","mediaGroup","muted","networkState","paused","playbackRate","played","preload","readyState","seekable","seeking","src","startDate","textTracks","videoTracks","volume"],methods:["addTextTrack","canPlayType","load","play","pause"],events:["abort","canplay","canplaythrough","durationchange","emptied","ended","error","loadeddata","loadedmetadata","loadstart","pause","play","playing","progress","ratechange","seeked","seeking","stalled","suspend","timeupdate","volumechange","waiting"],prototypes:["width","height","videoWidth","videoHeight","poster","webkitDecodedFrameCount","webkitDroppedFrameCount","playsInline","webLine truncated
|
||||
@@ -4,4 +4,4 @@
|
||||
* (c) 2017-2026 Harvey Zhao
|
||||
* Released under the MIT License.
|
||||
*/
|
||||
!function(t,e){"object"===typeof exports&&"undefined"!==typeof module?module.exports=e():"function"==typeof define&&define.amd?(t.Artplayer=e(),define(function(){return t.Artplayer})):(t="undefined"!==typeof globalThis?globalThis:t||self).Artplayer=e()}(this,function(){"use strict";var t,e=Object.defineProperty,r=Object.defineProperties,o=Object.getOwnPropertyDescriptors,a=Object.getOwnPropertySymbols,n=Object.prototype.hasOwnProperty,i=Object.prototype.propertyIsEnumerable,s=(t,r,o)=>r in t?e(t,r,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[r]=o,l=(t,e)=>{for(var r in e||(e={}))n.call(e,r)&&s(t,r,e[r]);if(a)for(var r of a(e))i.call(e,r)&&s(t,r,e[r]);return t},c=(t,e)=>r(t,o(e)),d=(t,e,r)=>new Promise((o,a)=>{var n=t=>{try{s(r.next(t))}catch(e){a(e)}},i=t=>{try{s(r.throw(t))}catch(e){a(e)}},s=t=>t.done?o(t.value):Promise.resolve(t.value).then(n,i);s((r=r.apply(t,e)).next())});function p(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var h,u={exports:{}};var m=(h||(h=1,u.exports=function(){function t(e){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(e)}var e=Object.prototype.toString,r=function(r){if(void 0===r)return"undefined";if(null===r)return"null";var a=t(r);if("boolean"===a)return"boolean";if("string"===a)return"string";if("number"===a)return"number";if("symbol"===a)return"symbol";if("function"===a)return"GeneratorFunction"===o(r)?"generatorfunction":"function";if(function(t){return Array.isArray?Array.isArray(t):t instanceof Array}(r))return"array";if(function(t){return!(!t.constructor||"function"!=typeof t.constructor.isBuffer)&&t.constructor.isBuffer(t)}(r))return"buffer";if(function(t){try{if("number"==typeof t.length&&"function"==typeof t.callee)return!0}catch(e){if(-1!==e.message.indexOf("callee"))return!0}return!1}(r))return"arguments";if(function(t){return t instanceof Date||"function"==typeof t.toDateString&&"function"==typeof t.getDate&&"function"==typeof t.setDate}(r))return"date";if(function(t){return t instanceof Error||"string"==typeof t.message&&t.constructor&&"number"==typeof t.constructor.stackTraceLimit}(r))return"error";if(function(t){return t instanceof RegExp||"string"==typeof t.flags&&"boolean"==typeof t.ignoreCase&&"boolean"==typeof t.multiline&&"boolean"==typeof t.global}(r))return"regexp";switch(o(r)){case"Symbol":return"symbol";case"Promise":return"promise";case"WeakMap":return"weakmap";case"WeakSet":return"weakset";case"Map":return"map";case"Set":return"set";case"Int8Array":return"int8array";case"Uint8Array":return"uint8array";case"Uint8ClampedArray":return"uint8clampedarray";case"Int16Array":return"int16array";case"Uint16Array":return"uint16array";case"Int32Array":return"int32array";case"Uint32Array":return"uint32array";case"Float32Array":return"float32array";case"Float64Array":return"float64array"}if(function(t){return"function"==typeof t.throw&&"function"==typeof t.return&&"function"==typeof t.next}(r))return"generator";switch(a=e.call(r)){case"[object Object]":return"object";case"[object Map Iterator]":return"mapiterator";case"[object Set Iterator]":return"setiterator";case"[object String Iterator]":return"stringiterator";case"[object Array Iterator]":return"arrayiterator"}return a.slice(8,-1).toLowerCase().replace(/\s/g,"")};function o(t){return t.constructor?t.constructor.name:null}function a(t,e){var o=2<arguments.length&&void 0!==arguments[2]?arguments[2]:["option"];return n(t,e,o),i(t,e,o),function(t,e,o){var s=r(e),l=r(t);if("object"===s){if("object"!==l)throw new Error("[Type Error]: '".concat(o.join("."),"' require 'object' type, but got '").concat(l,"'"));Object.keys(e).forEach(function(r){var s=t[r],l=e[r],c=o.slice();c.push(r),n(s,l,c),i(s,l,c),a(s,l,c)})}if("array"===s){if("array"!==l)throw new Error("[Type Error]: '".concat(o.join("."),"' require 'array' type, but got '").concat(l,"'"));t.forEach(function(r,s){var l=t[s],c=e[s]||e[0],d=o.slice();d.push(s),n(l,c,d),i(l,c,d),a(l,c,d)})}}(t,e,o),t}function n(t,e,o){if("string"===r(e)){var a=r(t);if("?"===e[0]&&(e=e.slice(1)+"|undefined"),!(-1<e.indexOf("|")?e.split("|").map(function(t){return t.toLowerCase().trim()}).filter(Boolean).some(function(t){return a===t}):e.toLowerCase().trim()===a))throw new Error("[Type Error]: '".concat(o.join("."),"' require '").concat(e,"' type, but got '").concat(a,"'"))}}function i(t,e,o){if("function"===r(e)){var a=e(t,r(t),o);if(!0!==a){var n=r(a);throw"string"===n?new Error(a):"error"===n?a:new Error("[Validator Error]: The scheme for '".concat(o.join("."),"' validator require return true, but got '").concat(a,"'"))}}}return a.kindOf=r,a}()),u.exports);const f=p(m),g="5.4.1",v={properties:["audioTracks","autoplay","buffered","controller","controls","crossOrigin","currentSrc","currentTime","defaultMuted","defaultPlaybackRate","duration","ended","error","loop","meLine truncated
|
||||
!function(t,e){"object"===typeof exports&&"undefined"!==typeof module?module.exports=e():"function"==typeof define&&define.amd?(t.Artplayer=e(),define(function(){return t.Artplayer})):(t="undefined"!==typeof globalThis?globalThis:t||self).Artplayer=e()}(this,function(){"use strict";var t,e=Object.defineProperty,r=Object.defineProperties,o=Object.getOwnPropertyDescriptors,a=Object.getOwnPropertySymbols,n=Object.prototype.hasOwnProperty,i=Object.prototype.propertyIsEnumerable,s=(t,r,o)=>r in t?e(t,r,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[r]=o,l=(t,e)=>{for(var r in e||(e={}))n.call(e,r)&&s(t,r,e[r]);if(a)for(var r of a(e))i.call(e,r)&&s(t,r,e[r]);return t},c=(t,e)=>r(t,o(e)),d=(t,e,r)=>new Promise((o,a)=>{var n=t=>{try{s(r.next(t))}catch(e){a(e)}},i=t=>{try{s(r.throw(t))}catch(e){a(e)}},s=t=>t.done?o(t.value):Promise.resolve(t.value).then(n,i);s((r=r.apply(t,e)).next())});function p(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var h,u={exports:{}};var m=(h||(h=1,u.exports=function(){function t(e){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(e)}var e=Object.prototype.toString,r=function(r){if(void 0===r)return"undefined";if(null===r)return"null";var a=t(r);if("boolean"===a)return"boolean";if("string"===a)return"string";if("number"===a)return"number";if("symbol"===a)return"symbol";if("function"===a)return"GeneratorFunction"===o(r)?"generatorfunction":"function";if(function(t){return Array.isArray?Array.isArray(t):t instanceof Array}(r))return"array";if(function(t){return!(!t.constructor||"function"!=typeof t.constructor.isBuffer)&&t.constructor.isBuffer(t)}(r))return"buffer";if(function(t){try{if("number"==typeof t.length&&"function"==typeof t.callee)return!0}catch(e){if(-1!==e.message.indexOf("callee"))return!0}return!1}(r))return"arguments";if(function(t){return t instanceof Date||"function"==typeof t.toDateString&&"function"==typeof t.getDate&&"function"==typeof t.setDate}(r))return"date";if(function(t){return t instanceof Error||"string"==typeof t.message&&t.constructor&&"number"==typeof t.constructor.stackTraceLimit}(r))return"error";if(function(t){return t instanceof RegExp||"string"==typeof t.flags&&"boolean"==typeof t.ignoreCase&&"boolean"==typeof t.multiline&&"boolean"==typeof t.global}(r))return"regexp";switch(o(r)){case"Symbol":return"symbol";case"Promise":return"promise";case"WeakMap":return"weakmap";case"WeakSet":return"weakset";case"Map":return"map";case"Set":return"set";case"Int8Array":return"int8array";case"Uint8Array":return"uint8array";case"Uint8ClampedArray":return"uint8clampedarray";case"Int16Array":return"int16array";case"Uint16Array":return"uint16array";case"Int32Array":return"int32array";case"Uint32Array":return"uint32array";case"Float32Array":return"float32array";case"Float64Array":return"float64array"}if(function(t){return"function"==typeof t.throw&&"function"==typeof t.return&&"function"==typeof t.next}(r))return"generator";switch(a=e.call(r)){case"[object Object]":return"object";case"[object Map Iterator]":return"mapiterator";case"[object Set Iterator]":return"setiterator";case"[object String Iterator]":return"stringiterator";case"[object Array Iterator]":return"arrayiterator"}return a.slice(8,-1).toLowerCase().replace(/\s/g,"")};function o(t){return t.constructor?t.constructor.name:null}function a(t,e){var o=2<arguments.length&&void 0!==arguments[2]?arguments[2]:["option"];return n(t,e,o),i(t,e,o),function(t,e,o){var s=r(e),l=r(t);if("object"===s){if("object"!==l)throw new Error("[Type Error]: '".concat(o.join("."),"' require 'object' type, but got '").concat(l,"'"));Object.keys(e).forEach(function(r){var s=t[r],l=e[r],c=o.slice();c.push(r),n(s,l,c),i(s,l,c),a(s,l,c)})}if("array"===s){if("array"!==l)throw new Error("[Type Error]: '".concat(o.join("."),"' require 'array' type, but got '").concat(l,"'"));t.forEach(function(r,s){var l=t[s],c=e[s]||e[0],d=o.slice();d.push(s),n(l,c,d),i(l,c,d),a(l,c,d)})}}(t,e,o),t}function n(t,e,o){if("string"===r(e)){var a=r(t);if("?"===e[0]&&(e=e.slice(1)+"|undefined"),!(-1<e.indexOf("|")?e.split("|").map(function(t){return t.toLowerCase().trim()}).filter(Boolean).some(function(t){return a===t}):e.toLowerCase().trim()===a))throw new Error("[Type Error]: '".concat(o.join("."),"' require '").concat(e,"' type, but got '").concat(a,"'"))}}function i(t,e,o){if("function"===r(e)){var a=e(t,r(t),o);if(!0!==a){var n=r(a);throw"string"===n?new Error(a):"error"===n?a:new Error("[Validator Error]: The scheme for '".concat(o.join("."),"' validator require return true, but got '").concat(a,"'"))}}}return a.kindOf=r,a}()),u.exports);const f=p(m),g="5.4.1",v={properties:["audioTracks","autoplay","buffered","controller","controls","crossOrigin","currentSrc","currentTime","defaultMuted","defaultPlaybackRate","duration","ended","error","loop","meLine truncated
|
||||
+18
-10
@@ -422,6 +422,13 @@ function errorHandle(condition, msg) {
|
||||
}
|
||||
return condition;
|
||||
}
|
||||
function silencePromise(value) {
|
||||
if (value && typeof value.catch === "function") {
|
||||
return value.catch(() => {
|
||||
});
|
||||
}
|
||||
return value;
|
||||
}
|
||||
function getExt(url) {
|
||||
if (url.includes("?")) {
|
||||
return getExt(url.split("?")[0]);
|
||||
@@ -636,6 +643,7 @@ const utils = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePropert
|
||||
setStyleText,
|
||||
setStyles,
|
||||
siblings,
|
||||
silencePromise,
|
||||
sleep,
|
||||
srtToVtt,
|
||||
supportsFlex,
|
||||
@@ -1166,7 +1174,7 @@ function playAndPause(option) {
|
||||
tooltip($play, i18n.get("Play"));
|
||||
tooltip($pause, i18n.get("Pause"));
|
||||
proxy($play, "click", () => {
|
||||
art.play();
|
||||
silencePromise(art.play());
|
||||
});
|
||||
proxy($pause, "click", () => {
|
||||
art.pause();
|
||||
@@ -1731,10 +1739,10 @@ function clickInit(art, events) {
|
||||
art.emit("click", event);
|
||||
if (isMobile) {
|
||||
if (!art.isLock && MOBILE_CLICK_PLAY) {
|
||||
art.toggle();
|
||||
silencePromise(art.toggle());
|
||||
}
|
||||
} else {
|
||||
art.toggle();
|
||||
silencePromise(art.toggle());
|
||||
}
|
||||
clickTimes = clicks;
|
||||
break;
|
||||
@@ -1742,7 +1750,7 @@ function clickInit(art, events) {
|
||||
art.emit("dblclick", event);
|
||||
if (isMobile) {
|
||||
if (!art.isLock && MOBILE_DBCLICK_PLAY) {
|
||||
art.toggle();
|
||||
silencePromise(art.toggle());
|
||||
}
|
||||
} else {
|
||||
if (DBCLICK_FULLSCREEN) {
|
||||
@@ -2024,7 +2032,7 @@ class Hotkey {
|
||||
}
|
||||
});
|
||||
this.add("Space", () => {
|
||||
this.art.toggle();
|
||||
silencePromise(this.art.toggle());
|
||||
});
|
||||
this.add("ArrowLeft", () => {
|
||||
this.art.backward = constructor.SEEK_STEP;
|
||||
@@ -2275,7 +2283,7 @@ class Mask extends Component {
|
||||
setStyle($state, "display", "none");
|
||||
setStyle($error, "display", null);
|
||||
});
|
||||
events.proxy(template.$state, "click", () => art.play());
|
||||
events.proxy(template.$state, "click", () => silencePromise(art.play()));
|
||||
}
|
||||
}
|
||||
class Notice {
|
||||
@@ -2499,7 +2507,7 @@ function eventInit(art) {
|
||||
art.on("video:ended", () => {
|
||||
if (option.loop) {
|
||||
art.seek = 0;
|
||||
art.play();
|
||||
silencePromise(art.play());
|
||||
art.controls.show = false;
|
||||
art.mask.show = false;
|
||||
} else {
|
||||
@@ -2885,7 +2893,7 @@ function miniMix(art) {
|
||||
const $state = append($mini2, `<div class="art-mini-state"></div>`);
|
||||
const $play = append($state, icons.play);
|
||||
const $pause = append($state, icons.pause);
|
||||
proxy($play, "click", () => art.play());
|
||||
proxy($play, "click", () => silencePromise(art.play()));
|
||||
proxy($pause, "click", () => art.pause());
|
||||
initState($play, $pause);
|
||||
art.on("video:playing", () => initState($play, $pause));
|
||||
@@ -3339,7 +3347,7 @@ function switchMix(art) {
|
||||
art.playbackRate = playbackRate2;
|
||||
art.aspectRatio = aspectRatio2;
|
||||
if (playing) {
|
||||
await art.play();
|
||||
await silencePromise(art.play());
|
||||
}
|
||||
art.notice.show = "";
|
||||
resolve();
|
||||
@@ -3699,7 +3707,7 @@ function autoPlayback(art) {
|
||||
});
|
||||
proxy($jump, "click", () => {
|
||||
art.seek = currentTime;
|
||||
art.play();
|
||||
silencePromise(art.play());
|
||||
setStyle($poster, "display", "none");
|
||||
setStyle($autoPlayback, "display", "none");
|
||||
});
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
"build:docs": "node ./scripts/build-docs.js",
|
||||
"build:i18n": "node ./scripts/build-i18n.js",
|
||||
"build:test": "node ./scripts/build-test.js",
|
||||
"test:playback": "node --test test/playback.test.js",
|
||||
"trans:docs": "node ./scripts/trans-docs.js",
|
||||
"create:plugin": "node ./scripts/plugin/create.js",
|
||||
"dev": "npx cross-env NODE_ENV=development node ./scripts/dev.js",
|
||||
|
||||
Vendored
+1
-1
@@ -4,4 +4,4 @@
|
||||
* (c) 2017-2026 Harvey Zhao
|
||||
* Released under the MIT License.
|
||||
*/
|
||||
!function(t,e){"object"===typeof exports&&"undefined"!==typeof module?module.exports=e():"function"==typeof define&&define.amd?(t.Artplayer=e(),define(function(){return t.Artplayer})):(t="undefined"!==typeof globalThis?globalThis:t||self).Artplayer=e()}(this,function(){"use strict";function t(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var e,r={exports:{}};var a=(e||(e=1,r.exports=function(){function t(e){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(e)}var e=Object.prototype.toString,r=function(r){if(void 0===r)return"undefined";if(null===r)return"null";var o=t(r);if("boolean"===o)return"boolean";if("string"===o)return"string";if("number"===o)return"number";if("symbol"===o)return"symbol";if("function"===o)return"GeneratorFunction"===a(r)?"generatorfunction":"function";if(function(t){return Array.isArray?Array.isArray(t):t instanceof Array}(r))return"array";if(function(t){return!(!t.constructor||"function"!=typeof t.constructor.isBuffer)&&t.constructor.isBuffer(t)}(r))return"buffer";if(function(t){try{if("number"==typeof t.length&&"function"==typeof t.callee)return!0}catch(e){if(-1!==e.message.indexOf("callee"))return!0}return!1}(r))return"arguments";if(function(t){return t instanceof Date||"function"==typeof t.toDateString&&"function"==typeof t.getDate&&"function"==typeof t.setDate}(r))return"date";if(function(t){return t instanceof Error||"string"==typeof t.message&&t.constructor&&"number"==typeof t.constructor.stackTraceLimit}(r))return"error";if(function(t){return t instanceof RegExp||"string"==typeof t.flags&&"boolean"==typeof t.ignoreCase&&"boolean"==typeof t.multiline&&"boolean"==typeof t.global}(r))return"regexp";switch(a(r)){case"Symbol":return"symbol";case"Promise":return"promise";case"WeakMap":return"weakmap";case"WeakSet":return"weakset";case"Map":return"map";case"Set":return"set";case"Int8Array":return"int8array";case"Uint8Array":return"uint8array";case"Uint8ClampedArray":return"uint8clampedarray";case"Int16Array":return"int16array";case"Uint16Array":return"uint16array";case"Int32Array":return"int32array";case"Uint32Array":return"uint32array";case"Float32Array":return"float32array";case"Float64Array":return"float64array"}if(function(t){return"function"==typeof t.throw&&"function"==typeof t.return&&"function"==typeof t.next}(r))return"generator";switch(o=e.call(r)){case"[object Object]":return"object";case"[object Map Iterator]":return"mapiterator";case"[object Set Iterator]":return"setiterator";case"[object String Iterator]":return"stringiterator";case"[object Array Iterator]":return"arrayiterator"}return o.slice(8,-1).toLowerCase().replace(/\s/g,"")};function a(t){return t.constructor?t.constructor.name:null}function o(t,e){var a=2<arguments.length&&void 0!==arguments[2]?arguments[2]:["option"];return n(t,e,a),i(t,e,a),function(t,e,a){var s=r(e),l=r(t);if("object"===s){if("object"!==l)throw new Error("[Type Error]: '".concat(a.join("."),"' require 'object' type, but got '").concat(l,"'"));Object.keys(e).forEach(function(r){var s=t[r],l=e[r],c=a.slice();c.push(r),n(s,l,c),i(s,l,c),o(s,l,c)})}if("array"===s){if("array"!==l)throw new Error("[Type Error]: '".concat(a.join("."),"' require 'array' type, but got '").concat(l,"'"));t.forEach(function(r,s){var l=t[s],c=e[s]||e[0],d=a.slice();d.push(s),n(l,c,d),i(l,c,d),o(l,c,d)})}}(t,e,a),t}function n(t,e,a){if("string"===r(e)){var o=r(t);if("?"===e[0]&&(e=e.slice(1)+"|undefined"),!(-1<e.indexOf("|")?e.split("|").map(function(t){return t.toLowerCase().trim()}).filter(Boolean).some(function(t){return o===t}):e.toLowerCase().trim()===o))throw new Error("[Type Error]: '".concat(a.join("."),"' require '").concat(e,"' type, but got '").concat(o,"'"))}}function i(t,e,a){if("function"===r(e)){var o=e(t,r(t),a);if(!0!==o){var n=r(o);throw"string"===n?new Error(o):"error"===n?o:new Error("[Validator Error]: The scheme for '".concat(a.join("."),"' validator require return true, but got '").concat(o,"'"))}}}return o.kindOf=r,o}()),r.exports);const o=t(a),n="5.4.1",i={properties:["audioTracks","autoplay","buffered","controller","controls","crossOrigin","currentSrc","currentTime","defaultMuted","defaultPlaybackRate","duration","ended","error","loop","mediaGroup","muted","networkState","paused","playbackRate","played","preload","readyState","seekable","seeking","src","startDate","textTracks","videoTracks","volume"],methods:["addTextTrack","canPlayType","load","play","pause"],events:["abort","canplay","canplaythrough","durationchange","emptied","ended","error","loadeddata","loadedmetadata","loadstart","pause","play","playing","progress","ratechange","seeked","seeking","stalled","suspend","timeupdate","volumechange","waiting"],prototypes:["width","height","videoWidth","videoHeight","poster","webkitDecodedFrameCount","webkitDroppedFrameCount","playsInline","webLine truncated
|
||||
!function(t,e){"object"===typeof exports&&"undefined"!==typeof module?module.exports=e():"function"==typeof define&&define.amd?(t.Artplayer=e(),define(function(){return t.Artplayer})):(t="undefined"!==typeof globalThis?globalThis:t||self).Artplayer=e()}(this,function(){"use strict";function t(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var e,r={exports:{}};var a=(e||(e=1,r.exports=function(){function t(e){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(e)}var e=Object.prototype.toString,r=function(r){if(void 0===r)return"undefined";if(null===r)return"null";var o=t(r);if("boolean"===o)return"boolean";if("string"===o)return"string";if("number"===o)return"number";if("symbol"===o)return"symbol";if("function"===o)return"GeneratorFunction"===a(r)?"generatorfunction":"function";if(function(t){return Array.isArray?Array.isArray(t):t instanceof Array}(r))return"array";if(function(t){return!(!t.constructor||"function"!=typeof t.constructor.isBuffer)&&t.constructor.isBuffer(t)}(r))return"buffer";if(function(t){try{if("number"==typeof t.length&&"function"==typeof t.callee)return!0}catch(e){if(-1!==e.message.indexOf("callee"))return!0}return!1}(r))return"arguments";if(function(t){return t instanceof Date||"function"==typeof t.toDateString&&"function"==typeof t.getDate&&"function"==typeof t.setDate}(r))return"date";if(function(t){return t instanceof Error||"string"==typeof t.message&&t.constructor&&"number"==typeof t.constructor.stackTraceLimit}(r))return"error";if(function(t){return t instanceof RegExp||"string"==typeof t.flags&&"boolean"==typeof t.ignoreCase&&"boolean"==typeof t.multiline&&"boolean"==typeof t.global}(r))return"regexp";switch(a(r)){case"Symbol":return"symbol";case"Promise":return"promise";case"WeakMap":return"weakmap";case"WeakSet":return"weakset";case"Map":return"map";case"Set":return"set";case"Int8Array":return"int8array";case"Uint8Array":return"uint8array";case"Uint8ClampedArray":return"uint8clampedarray";case"Int16Array":return"int16array";case"Uint16Array":return"uint16array";case"Int32Array":return"int32array";case"Uint32Array":return"uint32array";case"Float32Array":return"float32array";case"Float64Array":return"float64array"}if(function(t){return"function"==typeof t.throw&&"function"==typeof t.return&&"function"==typeof t.next}(r))return"generator";switch(o=e.call(r)){case"[object Object]":return"object";case"[object Map Iterator]":return"mapiterator";case"[object Set Iterator]":return"setiterator";case"[object String Iterator]":return"stringiterator";case"[object Array Iterator]":return"arrayiterator"}return o.slice(8,-1).toLowerCase().replace(/\s/g,"")};function a(t){return t.constructor?t.constructor.name:null}function o(t,e){var a=2<arguments.length&&void 0!==arguments[2]?arguments[2]:["option"];return n(t,e,a),i(t,e,a),function(t,e,a){var s=r(e),l=r(t);if("object"===s){if("object"!==l)throw new Error("[Type Error]: '".concat(a.join("."),"' require 'object' type, but got '").concat(l,"'"));Object.keys(e).forEach(function(r){var s=t[r],l=e[r],c=a.slice();c.push(r),n(s,l,c),i(s,l,c),o(s,l,c)})}if("array"===s){if("array"!==l)throw new Error("[Type Error]: '".concat(a.join("."),"' require 'array' type, but got '").concat(l,"'"));t.forEach(function(r,s){var l=t[s],c=e[s]||e[0],d=a.slice();d.push(s),n(l,c,d),i(l,c,d),o(l,c,d)})}}(t,e,a),t}function n(t,e,a){if("string"===r(e)){var o=r(t);if("?"===e[0]&&(e=e.slice(1)+"|undefined"),!(-1<e.indexOf("|")?e.split("|").map(function(t){return t.toLowerCase().trim()}).filter(Boolean).some(function(t){return o===t}):e.toLowerCase().trim()===o))throw new Error("[Type Error]: '".concat(a.join("."),"' require '").concat(e,"' type, but got '").concat(o,"'"))}}function i(t,e,a){if("function"===r(e)){var o=e(t,r(t),a);if(!0!==o){var n=r(o);throw"string"===n?new Error(o):"error"===n?o:new Error("[Validator Error]: The scheme for '".concat(a.join("."),"' validator require return true, but got '").concat(o,"'"))}}}return o.kindOf=r,o}()),r.exports);const o=t(a),n="5.4.1",i={properties:["audioTracks","autoplay","buffered","controller","controls","crossOrigin","currentSrc","currentTime","defaultMuted","defaultPlaybackRate","duration","ended","error","loop","mediaGroup","muted","networkState","paused","playbackRate","played","preload","readyState","seekable","seeking","src","startDate","textTracks","videoTracks","volume"],methods:["addTextTrack","canPlayType","load","play","pause"],events:["abort","canplay","canplaythrough","durationchange","emptied","ended","error","loadeddata","loadedmetadata","loadstart","pause","play","playing","progress","ratechange","seeked","seeking","stalled","suspend","timeupdate","volumechange","waiting"],prototypes:["width","height","videoWidth","videoHeight","poster","webkitDecodedFrameCount","webkitDroppedFrameCount","playsInline","webLine truncated
|
||||
+1
-1
@@ -4,4 +4,4 @@
|
||||
* (c) 2017-2026 Harvey Zhao
|
||||
* Released under the MIT License.
|
||||
*/
|
||||
!function(t,e){"object"===typeof exports&&"undefined"!==typeof module?module.exports=e():"function"==typeof define&&define.amd?(t.Artplayer=e(),define(function(){return t.Artplayer})):(t="undefined"!==typeof globalThis?globalThis:t||self).Artplayer=e()}(this,function(){"use strict";var t,e=Object.defineProperty,r=Object.defineProperties,o=Object.getOwnPropertyDescriptors,a=Object.getOwnPropertySymbols,n=Object.prototype.hasOwnProperty,i=Object.prototype.propertyIsEnumerable,s=(t,r,o)=>r in t?e(t,r,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[r]=o,l=(t,e)=>{for(var r in e||(e={}))n.call(e,r)&&s(t,r,e[r]);if(a)for(var r of a(e))i.call(e,r)&&s(t,r,e[r]);return t},c=(t,e)=>r(t,o(e)),d=(t,e,r)=>new Promise((o,a)=>{var n=t=>{try{s(r.next(t))}catch(e){a(e)}},i=t=>{try{s(r.throw(t))}catch(e){a(e)}},s=t=>t.done?o(t.value):Promise.resolve(t.value).then(n,i);s((r=r.apply(t,e)).next())});function p(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var h,u={exports:{}};var m=(h||(h=1,u.exports=function(){function t(e){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(e)}var e=Object.prototype.toString,r=function(r){if(void 0===r)return"undefined";if(null===r)return"null";var a=t(r);if("boolean"===a)return"boolean";if("string"===a)return"string";if("number"===a)return"number";if("symbol"===a)return"symbol";if("function"===a)return"GeneratorFunction"===o(r)?"generatorfunction":"function";if(function(t){return Array.isArray?Array.isArray(t):t instanceof Array}(r))return"array";if(function(t){return!(!t.constructor||"function"!=typeof t.constructor.isBuffer)&&t.constructor.isBuffer(t)}(r))return"buffer";if(function(t){try{if("number"==typeof t.length&&"function"==typeof t.callee)return!0}catch(e){if(-1!==e.message.indexOf("callee"))return!0}return!1}(r))return"arguments";if(function(t){return t instanceof Date||"function"==typeof t.toDateString&&"function"==typeof t.getDate&&"function"==typeof t.setDate}(r))return"date";if(function(t){return t instanceof Error||"string"==typeof t.message&&t.constructor&&"number"==typeof t.constructor.stackTraceLimit}(r))return"error";if(function(t){return t instanceof RegExp||"string"==typeof t.flags&&"boolean"==typeof t.ignoreCase&&"boolean"==typeof t.multiline&&"boolean"==typeof t.global}(r))return"regexp";switch(o(r)){case"Symbol":return"symbol";case"Promise":return"promise";case"WeakMap":return"weakmap";case"WeakSet":return"weakset";case"Map":return"map";case"Set":return"set";case"Int8Array":return"int8array";case"Uint8Array":return"uint8array";case"Uint8ClampedArray":return"uint8clampedarray";case"Int16Array":return"int16array";case"Uint16Array":return"uint16array";case"Int32Array":return"int32array";case"Uint32Array":return"uint32array";case"Float32Array":return"float32array";case"Float64Array":return"float64array"}if(function(t){return"function"==typeof t.throw&&"function"==typeof t.return&&"function"==typeof t.next}(r))return"generator";switch(a=e.call(r)){case"[object Object]":return"object";case"[object Map Iterator]":return"mapiterator";case"[object Set Iterator]":return"setiterator";case"[object String Iterator]":return"stringiterator";case"[object Array Iterator]":return"arrayiterator"}return a.slice(8,-1).toLowerCase().replace(/\s/g,"")};function o(t){return t.constructor?t.constructor.name:null}function a(t,e){var o=2<arguments.length&&void 0!==arguments[2]?arguments[2]:["option"];return n(t,e,o),i(t,e,o),function(t,e,o){var s=r(e),l=r(t);if("object"===s){if("object"!==l)throw new Error("[Type Error]: '".concat(o.join("."),"' require 'object' type, but got '").concat(l,"'"));Object.keys(e).forEach(function(r){var s=t[r],l=e[r],c=o.slice();c.push(r),n(s,l,c),i(s,l,c),a(s,l,c)})}if("array"===s){if("array"!==l)throw new Error("[Type Error]: '".concat(o.join("."),"' require 'array' type, but got '").concat(l,"'"));t.forEach(function(r,s){var l=t[s],c=e[s]||e[0],d=o.slice();d.push(s),n(l,c,d),i(l,c,d),a(l,c,d)})}}(t,e,o),t}function n(t,e,o){if("string"===r(e)){var a=r(t);if("?"===e[0]&&(e=e.slice(1)+"|undefined"),!(-1<e.indexOf("|")?e.split("|").map(function(t){return t.toLowerCase().trim()}).filter(Boolean).some(function(t){return a===t}):e.toLowerCase().trim()===a))throw new Error("[Type Error]: '".concat(o.join("."),"' require '").concat(e,"' type, but got '").concat(a,"'"))}}function i(t,e,o){if("function"===r(e)){var a=e(t,r(t),o);if(!0!==a){var n=r(a);throw"string"===n?new Error(a):"error"===n?a:new Error("[Validator Error]: The scheme for '".concat(o.join("."),"' validator require return true, but got '").concat(a,"'"))}}}return a.kindOf=r,a}()),u.exports);const f=p(m),g="5.4.1",v={properties:["audioTracks","autoplay","buffered","controller","controls","crossOrigin","currentSrc","currentTime","defaultMuted","defaultPlaybackRate","duration","ended","error","loop","meLine truncated
|
||||
!function(t,e){"object"===typeof exports&&"undefined"!==typeof module?module.exports=e():"function"==typeof define&&define.amd?(t.Artplayer=e(),define(function(){return t.Artplayer})):(t="undefined"!==typeof globalThis?globalThis:t||self).Artplayer=e()}(this,function(){"use strict";var t,e=Object.defineProperty,r=Object.defineProperties,o=Object.getOwnPropertyDescriptors,a=Object.getOwnPropertySymbols,n=Object.prototype.hasOwnProperty,i=Object.prototype.propertyIsEnumerable,s=(t,r,o)=>r in t?e(t,r,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[r]=o,l=(t,e)=>{for(var r in e||(e={}))n.call(e,r)&&s(t,r,e[r]);if(a)for(var r of a(e))i.call(e,r)&&s(t,r,e[r]);return t},c=(t,e)=>r(t,o(e)),d=(t,e,r)=>new Promise((o,a)=>{var n=t=>{try{s(r.next(t))}catch(e){a(e)}},i=t=>{try{s(r.throw(t))}catch(e){a(e)}},s=t=>t.done?o(t.value):Promise.resolve(t.value).then(n,i);s((r=r.apply(t,e)).next())});function p(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var h,u={exports:{}};var m=(h||(h=1,u.exports=function(){function t(e){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(e)}var e=Object.prototype.toString,r=function(r){if(void 0===r)return"undefined";if(null===r)return"null";var a=t(r);if("boolean"===a)return"boolean";if("string"===a)return"string";if("number"===a)return"number";if("symbol"===a)return"symbol";if("function"===a)return"GeneratorFunction"===o(r)?"generatorfunction":"function";if(function(t){return Array.isArray?Array.isArray(t):t instanceof Array}(r))return"array";if(function(t){return!(!t.constructor||"function"!=typeof t.constructor.isBuffer)&&t.constructor.isBuffer(t)}(r))return"buffer";if(function(t){try{if("number"==typeof t.length&&"function"==typeof t.callee)return!0}catch(e){if(-1!==e.message.indexOf("callee"))return!0}return!1}(r))return"arguments";if(function(t){return t instanceof Date||"function"==typeof t.toDateString&&"function"==typeof t.getDate&&"function"==typeof t.setDate}(r))return"date";if(function(t){return t instanceof Error||"string"==typeof t.message&&t.constructor&&"number"==typeof t.constructor.stackTraceLimit}(r))return"error";if(function(t){return t instanceof RegExp||"string"==typeof t.flags&&"boolean"==typeof t.ignoreCase&&"boolean"==typeof t.multiline&&"boolean"==typeof t.global}(r))return"regexp";switch(o(r)){case"Symbol":return"symbol";case"Promise":return"promise";case"WeakMap":return"weakmap";case"WeakSet":return"weakset";case"Map":return"map";case"Set":return"set";case"Int8Array":return"int8array";case"Uint8Array":return"uint8array";case"Uint8ClampedArray":return"uint8clampedarray";case"Int16Array":return"int16array";case"Uint16Array":return"uint16array";case"Int32Array":return"int32array";case"Uint32Array":return"uint32array";case"Float32Array":return"float32array";case"Float64Array":return"float64array"}if(function(t){return"function"==typeof t.throw&&"function"==typeof t.return&&"function"==typeof t.next}(r))return"generator";switch(a=e.call(r)){case"[object Object]":return"object";case"[object Map Iterator]":return"mapiterator";case"[object Set Iterator]":return"setiterator";case"[object String Iterator]":return"stringiterator";case"[object Array Iterator]":return"arrayiterator"}return a.slice(8,-1).toLowerCase().replace(/\s/g,"")};function o(t){return t.constructor?t.constructor.name:null}function a(t,e){var o=2<arguments.length&&void 0!==arguments[2]?arguments[2]:["option"];return n(t,e,o),i(t,e,o),function(t,e,o){var s=r(e),l=r(t);if("object"===s){if("object"!==l)throw new Error("[Type Error]: '".concat(o.join("."),"' require 'object' type, but got '").concat(l,"'"));Object.keys(e).forEach(function(r){var s=t[r],l=e[r],c=o.slice();c.push(r),n(s,l,c),i(s,l,c),a(s,l,c)})}if("array"===s){if("array"!==l)throw new Error("[Type Error]: '".concat(o.join("."),"' require 'array' type, but got '").concat(l,"'"));t.forEach(function(r,s){var l=t[s],c=e[s]||e[0],d=o.slice();d.push(s),n(l,c,d),i(l,c,d),a(l,c,d)})}}(t,e,o),t}function n(t,e,o){if("string"===r(e)){var a=r(t);if("?"===e[0]&&(e=e.slice(1)+"|undefined"),!(-1<e.indexOf("|")?e.split("|").map(function(t){return t.toLowerCase().trim()}).filter(Boolean).some(function(t){return a===t}):e.toLowerCase().trim()===a))throw new Error("[Type Error]: '".concat(o.join("."),"' require '").concat(e,"' type, but got '").concat(a,"'"))}}function i(t,e,o){if("function"===r(e)){var a=e(t,r(t),o);if(!0!==a){var n=r(a);throw"string"===n?new Error(a):"error"===n?a:new Error("[Validator Error]: The scheme for '".concat(o.join("."),"' validator require return true, but got '").concat(a,"'"))}}}return a.kindOf=r,a}()),u.exports);const f=p(m),g="5.4.1",v={properties:["audioTracks","autoplay","buffered","controller","controls","crossOrigin","currentSrc","currentTime","defaultMuted","defaultPlaybackRate","duration","ended","error","loop","meLine truncated
|
||||
+18
-10
@@ -422,6 +422,13 @@ function errorHandle(condition, msg) {
|
||||
}
|
||||
return condition;
|
||||
}
|
||||
function silencePromise(value) {
|
||||
if (value && typeof value.catch === "function") {
|
||||
return value.catch(() => {
|
||||
});
|
||||
}
|
||||
return value;
|
||||
}
|
||||
function getExt(url) {
|
||||
if (url.includes("?")) {
|
||||
return getExt(url.split("?")[0]);
|
||||
@@ -636,6 +643,7 @@ const utils = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePropert
|
||||
setStyleText,
|
||||
setStyles,
|
||||
siblings,
|
||||
silencePromise,
|
||||
sleep,
|
||||
srtToVtt,
|
||||
supportsFlex,
|
||||
@@ -1166,7 +1174,7 @@ function playAndPause(option) {
|
||||
tooltip($play, i18n.get("Play"));
|
||||
tooltip($pause, i18n.get("Pause"));
|
||||
proxy($play, "click", () => {
|
||||
art.play();
|
||||
silencePromise(art.play());
|
||||
});
|
||||
proxy($pause, "click", () => {
|
||||
art.pause();
|
||||
@@ -1731,10 +1739,10 @@ function clickInit(art, events) {
|
||||
art.emit("click", event);
|
||||
if (isMobile) {
|
||||
if (!art.isLock && MOBILE_CLICK_PLAY) {
|
||||
art.toggle();
|
||||
silencePromise(art.toggle());
|
||||
}
|
||||
} else {
|
||||
art.toggle();
|
||||
silencePromise(art.toggle());
|
||||
}
|
||||
clickTimes = clicks;
|
||||
break;
|
||||
@@ -1742,7 +1750,7 @@ function clickInit(art, events) {
|
||||
art.emit("dblclick", event);
|
||||
if (isMobile) {
|
||||
if (!art.isLock && MOBILE_DBCLICK_PLAY) {
|
||||
art.toggle();
|
||||
silencePromise(art.toggle());
|
||||
}
|
||||
} else {
|
||||
if (DBCLICK_FULLSCREEN) {
|
||||
@@ -2024,7 +2032,7 @@ class Hotkey {
|
||||
}
|
||||
});
|
||||
this.add("Space", () => {
|
||||
this.art.toggle();
|
||||
silencePromise(this.art.toggle());
|
||||
});
|
||||
this.add("ArrowLeft", () => {
|
||||
this.art.backward = constructor.SEEK_STEP;
|
||||
@@ -2275,7 +2283,7 @@ class Mask extends Component {
|
||||
setStyle($state, "display", "none");
|
||||
setStyle($error, "display", null);
|
||||
});
|
||||
events.proxy(template.$state, "click", () => art.play());
|
||||
events.proxy(template.$state, "click", () => silencePromise(art.play()));
|
||||
}
|
||||
}
|
||||
class Notice {
|
||||
@@ -2499,7 +2507,7 @@ function eventInit(art) {
|
||||
art.on("video:ended", () => {
|
||||
if (option.loop) {
|
||||
art.seek = 0;
|
||||
art.play();
|
||||
silencePromise(art.play());
|
||||
art.controls.show = false;
|
||||
art.mask.show = false;
|
||||
} else {
|
||||
@@ -2885,7 +2893,7 @@ function miniMix(art) {
|
||||
const $state = append($mini2, `<div class="art-mini-state"></div>`);
|
||||
const $play = append($state, icons.play);
|
||||
const $pause = append($state, icons.pause);
|
||||
proxy($play, "click", () => art.play());
|
||||
proxy($play, "click", () => silencePromise(art.play()));
|
||||
proxy($pause, "click", () => art.pause());
|
||||
initState($play, $pause);
|
||||
art.on("video:playing", () => initState($play, $pause));
|
||||
@@ -3339,7 +3347,7 @@ function switchMix(art) {
|
||||
art.playbackRate = playbackRate2;
|
||||
art.aspectRatio = aspectRatio2;
|
||||
if (playing) {
|
||||
await art.play();
|
||||
await silencePromise(art.play());
|
||||
}
|
||||
art.notice.show = "";
|
||||
resolve();
|
||||
@@ -3699,7 +3707,7 @@ function autoPlayback(art) {
|
||||
});
|
||||
proxy($jump, "click", () => {
|
||||
art.seek = currentTime;
|
||||
art.play();
|
||||
silencePromise(art.play());
|
||||
setStyle($poster, "display", "none");
|
||||
setStyle($autoPlayback, "display", "none");
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { append, setStyle, tooltip } from '../utils'
|
||||
import { append, setStyle, silencePromise, tooltip } from '../utils'
|
||||
|
||||
export default function playAndPause(option) {
|
||||
return art => ({
|
||||
@@ -12,7 +12,7 @@ export default function playAndPause(option) {
|
||||
tooltip($pause, i18n.get('Pause'))
|
||||
|
||||
proxy($play, 'click', () => {
|
||||
art.play()
|
||||
silencePromise(art.play())
|
||||
})
|
||||
|
||||
proxy($pause, 'click', () => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { includeFromEvent, isMobile } from '../utils'
|
||||
import { includeFromEvent, isMobile, silencePromise } from '../utils'
|
||||
|
||||
export default function clickInit(art, events) {
|
||||
const {
|
||||
@@ -35,11 +35,11 @@ export default function clickInit(art, events) {
|
||||
|
||||
if (isMobile) {
|
||||
if (!art.isLock && MOBILE_CLICK_PLAY) {
|
||||
art.toggle()
|
||||
silencePromise(art.toggle())
|
||||
}
|
||||
}
|
||||
else {
|
||||
art.toggle()
|
||||
silencePromise(art.toggle())
|
||||
}
|
||||
clickTimes = clicks
|
||||
break
|
||||
@@ -48,7 +48,7 @@ export default function clickInit(art, events) {
|
||||
|
||||
if (isMobile) {
|
||||
if (!art.isLock && MOBILE_DBCLICK_PLAY) {
|
||||
art.toggle()
|
||||
silencePromise(art.toggle())
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { isMobile } from './utils'
|
||||
import { isMobile, silencePromise } from './utils'
|
||||
|
||||
export default class Hotkey {
|
||||
constructor(art) {
|
||||
@@ -21,7 +21,7 @@ export default class Hotkey {
|
||||
})
|
||||
|
||||
this.add('Space', () => {
|
||||
this.art.toggle()
|
||||
silencePromise(this.art.toggle())
|
||||
})
|
||||
|
||||
this.add('ArrowLeft', () => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { append, setStyle } from './utils'
|
||||
import { append, setStyle, silencePromise } from './utils'
|
||||
import Component from './utils/component'
|
||||
|
||||
export default class Mask extends Component {
|
||||
@@ -18,6 +18,6 @@ export default class Mask extends Component {
|
||||
setStyle($error, 'display', null)
|
||||
})
|
||||
|
||||
events.proxy(template.$state, 'click', () => art.play())
|
||||
events.proxy(template.$state, 'click', () => silencePromise(art.play()))
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import config from '../config'
|
||||
import { addClass, isMobile, setStyle, sleep } from '../utils'
|
||||
import { addClass, isMobile, setStyle, silencePromise, sleep } from '../utils'
|
||||
|
||||
export default function eventInit(art) {
|
||||
const {
|
||||
@@ -51,7 +51,7 @@ export default function eventInit(art) {
|
||||
art.on('video:ended', () => {
|
||||
if (option.loop) {
|
||||
art.seek = 0
|
||||
art.play()
|
||||
silencePromise(art.play())
|
||||
art.controls.show = false
|
||||
art.mask.show = false
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { addClass, append, createElement, def, getRect, hasClass, isInViewport, removeClass, setStyle } from '../utils'
|
||||
import { addClass, append, createElement, def, getRect, hasClass, isInViewport, removeClass, setStyle, silencePromise } from '../utils'
|
||||
|
||||
export default function miniMix(art) {
|
||||
const {
|
||||
@@ -53,7 +53,7 @@ export default function miniMix(art) {
|
||||
const $state = append($mini, `<div class="art-mini-state"></div>`)
|
||||
const $play = append($state, icons.play)
|
||||
const $pause = append($state, icons.pause)
|
||||
proxy($play, 'click', () => art.play())
|
||||
proxy($play, 'click', () => silencePromise(art.play()))
|
||||
proxy($pause, 'click', () => art.pause())
|
||||
initState($play, $pause)
|
||||
art.on('video:playing', () => initState($play, $pause))
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { def } from '../utils'
|
||||
import { def, silencePromise } from '../utils'
|
||||
|
||||
export default function switchMix(art) {
|
||||
function switchUrl(url, currentTime) {
|
||||
@@ -31,7 +31,7 @@ export default function switchMix(art) {
|
||||
art.aspectRatio = aspectRatio
|
||||
|
||||
if (playing) {
|
||||
await art.play()
|
||||
await silencePromise(art.play())
|
||||
}
|
||||
|
||||
art.notice.show = ''
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { append, query, secondToTime, setStyle } from '../utils'
|
||||
import { append, query, secondToTime, setStyle, silencePromise } from '../utils'
|
||||
|
||||
export default function autoPlayback(art) {
|
||||
const {
|
||||
@@ -57,7 +57,7 @@ export default function autoPlayback(art) {
|
||||
|
||||
proxy($jump, 'click', () => {
|
||||
art.seek = currentTime
|
||||
art.play()
|
||||
silencePromise(art.play())
|
||||
setStyle($poster, 'display', 'none')
|
||||
setStyle($autoPlayback, 'display', 'none')
|
||||
})
|
||||
|
||||
@@ -14,3 +14,12 @@ export function errorHandle(condition, msg) {
|
||||
}
|
||||
return condition
|
||||
}
|
||||
|
||||
// Handle internal play rejections without changing the public play/toggle promises.
|
||||
// Values without catch (including synchronous pause results) pass through unchanged.
|
||||
export function silencePromise(value) {
|
||||
if (value && typeof value.catch === 'function') {
|
||||
return value.catch(() => {})
|
||||
}
|
||||
return value
|
||||
}
|
||||
Vendored
+1
@@ -43,6 +43,7 @@ export interface Utils {
|
||||
loadImg: (url: string, scale?: number) => Promise<HTMLImageElement>
|
||||
|
||||
errorHandle: <T extends boolean>(condition: T, msg: string) => T extends true ? T : never
|
||||
silencePromise: <T>(value: T) => T extends Promise<infer R> ? Promise<R | undefined> : T
|
||||
def: (obj: object, name: string, value: unknown) => void
|
||||
has: (obj: object, name: PropertyKey) => boolean
|
||||
get: (obj: object, name: PropertyKey) => PropertyDescriptor | undefined
|
||||
|
||||
@@ -0,0 +1,134 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import { Buffer } from 'node:buffer'
|
||||
// eslint-disable-next-line test/no-import-node-test -- Use the built-in runner without adding a test framework.
|
||||
import { mock, test } from 'node:test'
|
||||
import { setImmediate } from 'node:timers/promises'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import { build } from 'esbuild'
|
||||
|
||||
// Bundle the source modules so tests also work with Node 20's ESM resolution.
|
||||
const { outputFiles } = await build({
|
||||
stdin: {
|
||||
contents: `
|
||||
export { silencePromise } from './packages/artplayer/src/utils/error.js';
|
||||
export { default as Emitter } from './packages/artplayer/src/utils/emitter.js';
|
||||
export { default as Hotkey } from './packages/artplayer/src/hotkey.js';
|
||||
export { default as playMix } from './packages/artplayer/src/player/playMix.js';
|
||||
export { default as pauseMix } from './packages/artplayer/src/player/pauseMix.js';
|
||||
export { default as toggleMix } from './packages/artplayer/src/player/toggleMix.js';
|
||||
export { default as switchMix } from './packages/artplayer/src/player/switchMix.js';
|
||||
`,
|
||||
resolveDir: fileURLToPath(new URL('../', import.meta.url)),
|
||||
},
|
||||
bundle: true,
|
||||
write: false,
|
||||
platform: 'node',
|
||||
format: 'esm',
|
||||
})
|
||||
const { silencePromise, Emitter, Hotkey, playMix, pauseMix, toggleMix, switchMix } = await import(
|
||||
`data:text/javascript;base64,${Buffer.from(outputFiles[0].contents).toString('base64')}`,
|
||||
)
|
||||
|
||||
function createArt(play = () => Promise.resolve(), playing = false) {
|
||||
const art = Object.assign(new Emitter(), {
|
||||
url: 'old.mp4',
|
||||
currentTime: 37,
|
||||
aspectRatio: '16:9',
|
||||
playbackRate: 1.5,
|
||||
notice: { show: '' },
|
||||
i18n: { get: key => key },
|
||||
option: { hotkey: true, mutex: false },
|
||||
constructor: { instances: [] },
|
||||
template: {
|
||||
$video: {
|
||||
paused: !playing,
|
||||
play: mock.fn(play),
|
||||
pause() { this.paused = true },
|
||||
},
|
||||
},
|
||||
})
|
||||
Object.defineProperty(art, 'playing', { get: () => !art.template.$video.paused })
|
||||
for (const mix of [playMix, pauseMix, toggleMix, switchMix]) {
|
||||
mix(art)
|
||||
}
|
||||
return art
|
||||
}
|
||||
|
||||
test('silencePromise preserves fulfilled values and handles rejected promises', async () => {
|
||||
assert.equal(await silencePromise(Promise.resolve(42)), 42)
|
||||
assert.equal(await silencePromise(Promise.reject(new Error('interrupted'))), undefined)
|
||||
})
|
||||
|
||||
test('silencePromise passes through synchronous values and catch-less thenables', () => {
|
||||
const thenable = { then: (resolve, reject) => Promise.resolve(42).then(resolve, reject) }
|
||||
for (const value of [undefined, null, false, 42, thenable]) {
|
||||
assert.equal(silencePromise(value), value)
|
||||
}
|
||||
assert.equal(createArt(undefined, true).toggle(), undefined)
|
||||
})
|
||||
|
||||
for (const name of ['AbortError', 'NotAllowedError', 'NotSupportedError']) {
|
||||
test(`public play/toggle still reject with ${name}`, async () => {
|
||||
const error = new DOMException('Playback failed', name)
|
||||
const art = createArt(() => Promise.reject(error))
|
||||
const onPlay = mock.fn()
|
||||
art.on('play', onPlay)
|
||||
await assert.rejects(art.play(), actual => actual === error)
|
||||
await assert.rejects(art.toggle(), actual => actual === error)
|
||||
assert.equal(onPlay.mock.callCount(), 0)
|
||||
})
|
||||
|
||||
for (const method of ['switchUrl', 'switchQuality']) {
|
||||
test(`${method} settles when resume rejects with ${name}`, { timeout: 1000 }, async () => {
|
||||
const art = createArt(() => Promise.reject(new DOMException('Playback failed', name)), true)
|
||||
const switching = art[method]('new.mp4')
|
||||
art.currentTime = 0
|
||||
art.playbackRate = 1
|
||||
art.aspectRatio = 'default'
|
||||
art.emit('video:loadedmetadata')
|
||||
art.emit('video:canplay')
|
||||
await switching
|
||||
assert.equal(art.currentTime, method === 'switchQuality' ? 37 : 0)
|
||||
assert.equal(art.playbackRate, 1.5)
|
||||
assert.equal(art.aspectRatio, '16:9')
|
||||
assert.equal(art.notice.show, '')
|
||||
assert.equal(art.template.$video.play.mock.callCount(), 1)
|
||||
assert.deepEqual(Object.keys(art.e), [])
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
test('Space handles an interrupted pending play without an unhandled rejection', async () => {
|
||||
let rejectPlay
|
||||
const art = createArt(() => new Promise((resolve, reject) => {
|
||||
rejectPlay = reject
|
||||
}))
|
||||
const hotkey = new Hotkey(art)
|
||||
hotkey.keys.Space[0]()
|
||||
art.pause()
|
||||
rejectPlay(new DOMException('Interrupted by pause', 'AbortError'))
|
||||
// node:test fails on unhandled rejections, including those from event callbacks.
|
||||
await setImmediate()
|
||||
assert.equal(art.playing, false)
|
||||
})
|
||||
|
||||
test('switch resumes successfully and remains paused when previously paused', async () => {
|
||||
for (const playing of [true, false]) {
|
||||
const art = createArt(undefined, playing)
|
||||
const switching = art.switchUrl('new.mp4')
|
||||
art.emit('video:loadedmetadata')
|
||||
art.emit('video:canplay')
|
||||
await switching
|
||||
assert.equal(art.template.$video.play.mock.callCount(), playing ? 1 : 0)
|
||||
}
|
||||
})
|
||||
|
||||
test('source errors still reject switches and clean up listeners', async () => {
|
||||
const art = createArt()
|
||||
const error = new Error('Source failed to load')
|
||||
const rejected = assert.rejects(art.switchUrl('bad.mp4'), actual => actual === error)
|
||||
art.emit('video:error', error)
|
||||
await rejected
|
||||
assert.deepEqual(Object.keys(art.e), [])
|
||||
assert.equal(art.template.$video.play.mock.callCount(), 0)
|
||||
})
|
||||
@@ -0,0 +1,10 @@
|
||||
import type { Utils } from '../packages/artplayer/types/utils'
|
||||
|
||||
export function checkSilencePromiseTypes(utils: Utils, thenable: PromiseLike<number>) {
|
||||
const promise: Promise<number | undefined> = utils.silencePromise(Promise.resolve(42))
|
||||
const synchronous: undefined = utils.silencePromise(undefined)
|
||||
const unchanged: PromiseLike<number> = utils.silencePromise(thenable)
|
||||
// @ts-expect-error A catch-less thenable is not converted to a native Promise.
|
||||
utils.silencePromise(thenable).catch(() => {})
|
||||
return { promise, synchronous, unchanged }
|
||||
}
|
||||
Reference in new issue
Block a user