From a74e7bbff4e775b0e9022801c1bc806841454356 Mon Sep 17 00:00:00 2001 From: Harvey Zack Date: Sun, 15 Sep 2024 10:56:51 +0800 Subject: [PATCH] feat: createImageBitmap --- docs/assets/example/canvas.js | 2 +- docs/uncompiled/artplayer-proxy-canvas/index.js | 8 +++++--- docs/uncompiled/artplayer-proxy-canvas/index.js.map | 2 +- packages/artplayer-proxy-canvas/src/index.js | 10 +++++++--- .../types/artplayer-proxy-canvas.d.ts | 6 +----- 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/docs/assets/example/canvas.js b/docs/assets/example/canvas.js index 79528738d..25d772ecc 100644 --- a/docs/assets/example/canvas.js +++ b/docs/assets/example/canvas.js @@ -3,7 +3,7 @@ var art = new Artplayer({ container: '.artplayer-app', - url: '/assets/sample/video.mp4', + url: 'https://artplayer.org/assets/sample/video.mp4', poster: '/assets/sample/poster.jpg', volume: 0.5, autoplay: false, diff --git a/docs/uncompiled/artplayer-proxy-canvas/index.js b/docs/uncompiled/artplayer-proxy-canvas/index.js index 7421308cd..49e1081e7 100644 --- a/docs/uncompiled/artplayer-proxy-canvas/index.js +++ b/docs/uncompiled/artplayer-proxy-canvas/index.js @@ -207,9 +207,11 @@ function artplayerProxyCanvas() { } async function draw() { try { - const bitmap = await createImageBitmap(video); - ctx.drawImage(bitmap, 0, 0, canvas.width, canvas.height); - bitmap.close(); + if (typeof createImageBitmap !== "undefined") { + const bitmap = await createImageBitmap(video); + ctx.drawImage(bitmap, 0, 0, canvas.width, canvas.height); + bitmap.close(); + } else ctx.drawImage(video, 0, 0, canvas.width, canvas.height); art.emit("artplayerProxyCanvas:draw", ctx); } catch (error) { art.emit("artplayerProxyCanvas:error", error); diff --git a/docs/uncompiled/artplayer-proxy-canvas/index.js.map b/docs/uncompiled/artplayer-proxy-canvas/index.js.map index d39e620ec..8fd1bff42 100644 --- a/docs/uncompiled/artplayer-proxy-canvas/index.js.map +++ b/docs/uncompiled/artplayer-proxy-canvas/index.js.map @@ -1 +1 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,OAAO,KAAK,GAAG,MAAM,UAAU;gBAC/B,OAAO,MAAM,GAAG,MAAM,WAAW;YACrC;YAEA,IAAI,EAAE,CAAC,cAAc;gBACjB,qBAAqB;gBACrB,cAAc,sBAAsB;YACxC;YAEA,IAAI,EAAE,CAAC,eAAe;gBAClB,qBAAqB;YACzB;YAEA,IAAI,EAAE,CAAC,UAAU;gBACb;gBACA;YACJ;YAEA,IAAI,EAAE,CAAC,WAAW;gBACd,qBAAqB;YACzB;QACJ;IACJ;AACJ;AAEA,IAAI,OAAO,WAAW,aAClB,MAAM,CAAC,uBAAuB,GAAG;;;ACxIrC,QAAQ,cAAc,GAAG,SAAU,CAAC;IAClC,OAAO,KAAK,EAAE,UAAU,GAAG,IAAI;QAAC,SAAS;IAAC;AAC5C;AAEA,QAAQ,iBAAiB,GAAG,SAAU,CAAC;IACrC,OAAO,cAAc,CAAC,GAAG,cAAc;QAAC,OAAO;IAAI;AACrD;AAEA,QAAQ,SAAS,GAAG,SAAU,MAAM,EAAE,IAAI;IACxC,OAAO,IAAI,CAAC,QAAQ,OAAO,CAAC,SAAU,GAAG;QACvC,IACE,QAAQ,aACR,QAAQ,gBACR,OAAO,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,MAE3C;QAGF,OAAO,cAAc,CAAC,MAAM,KAAK;YAC/B,YAAY;YACZ,KAAK;gBACH,OAAO,MAAM,CAAC,IAAI;YACpB;QACF;IACF;IAEA,OAAO;AACT;AAEA,QAAQ,MAAM,GAAG,SAAU,IAAI,EAAE,QAAQ,EAAE,GAAG;IAC5C,OAAO,cAAc,CAAC,MAAM,UAAU;QACpC,YAAY;QACZ,KAAK;IACP;AACF","sources":["packages/artplayer-proxy-canvas/src/index.js","node_modules/@parcel/transformer-js/src/esmodule-helpers.js"],"sourcesContent":["export default function artplayerProxyCanvas() {\n return (art) => {\n const { option, constructor } = art;\n const { createElement, def } = constructor.utils;\n\n let animationId = null;\n const canvas = createElement('canvas');\n const ctx = canvas.getContext('2d');\n const video = createElement('video');\n\n const canvasProperties = {};\n const canvasKeys = ['width', 'height'];\n const { propertys, methods, prototypes, events } = constructor.config;\n const videoKeys = [...propertys, ...methods, ...prototypes];\n\n initCanvasProperties();\n proxyVideoToCanvas();\n setupEventListeners();\n setupArtPlayerEvents();\n\n return canvas;\n\n function initCanvasProperties() {\n canvasKeys.forEach((prop) => {\n canvasProperties[prop] = Object.getOwnPropertyDescriptor(HTMLCanvasElement.prototype, prop);\n });\n }\n\n function proxyVideoToCanvas() {\n videoKeys.forEach((key) => {\n if (canvasKeys.includes(key)) {\n def(canvas, key, {\n get() {\n return canvasProperties[key].get.call(this);\n },\n set(value) {\n canvasProperties[key].set.call(this, value);\n },\n });\n } else {\n def(canvas, key, {\n get() {\n const value = video[key];\n return typeof value === 'function' ? value.bind(video) : value;\n },\n set(value) {\n video[key] = value;\n },\n });\n }\n });\n }\n\n function setupEventListeners() {\n setTimeout(() => {\n events.forEach((event) => {\n art.proxy(video, event, (event) => {\n art.emit(`video:${event.type}`, event);\n });\n });\n });\n }\n\n async function draw() {\n try {\n const bitmap = await createImageBitmap(video);\n ctx.drawImage(bitmap, 0, 0, canvas.width, canvas.height);\n bitmap.close();\n art.emit('artplayerProxyCanvas:draw', ctx);\n } catch (error) {\n art.emit('artplayerProxyCanvas:error', error);\n }\n }\n\n async function animation() {\n await draw();\n animationId = requestAnimationFrame(animation);\n }\n\n function resize() {\n const player = art.template?.$player;\n if (!player || option.autoSize) return;\n\n const aspectRatio = video.videoWidth / video.videoHeight;\n const containerWidth = player.clientWidth;\n const containerHeight = player.clientHeight;\n const containerRatio = containerWidth / containerHeight;\n\n let canvasWidth, canvasHeight;\n if (containerRatio > aspectRatio) {\n canvasHeight = containerHeight;\n canvasWidth = canvasHeight * aspectRatio;\n } else {\n canvasWidth = containerWidth;\n canvasHeight = canvasWidth / aspectRatio;\n }\n\n canvas.width = canvasWidth;\n canvas.height = canvasHeight;\n\n const paddingLeft = (containerWidth - canvasWidth) / 2;\n const paddingTop = (containerHeight - canvasHeight) / 2;\n\n Object.assign(canvas.style, {\n padding: `${paddingTop}px ${paddingLeft}px`,\n });\n }\n\n function setupArtPlayerEvents() {\n art.on('video:loadedmetadata', async () => {\n canvas.width = video.videoWidth;\n canvas.height = video.videoHeight;\n });\n\n art.on('video:play', () => {\n cancelAnimationFrame(animationId);\n animationId = requestAnimationFrame(animation);\n });\n\n art.on('video:pause', () => {\n cancelAnimationFrame(animationId);\n });\n\n art.on('resize', () => {\n resize();\n draw();\n });\n\n art.on('destroy', () => {\n cancelAnimationFrame(animationId);\n });\n }\n };\n}\n\nif (typeof window !== 'undefined') {\n window['artplayerProxyCanvas'] = artplayerProxyCanvas;\n}\n","exports.interopDefault = function (a) {\n return a && a.__esModule ? a : {default: a};\n};\n\nexports.defineInteropFlag = function (a) {\n Object.defineProperty(a, '__esModule', {value: true});\n};\n\nexports.exportAll = function (source, dest) {\n Object.keys(source).forEach(function (key) {\n if (\n key === 'default' ||\n key === '__esModule' ||\n Object.prototype.hasOwnProperty.call(dest, key)\n ) {\n return;\n }\n\n Object.defineProperty(dest, key, {\n enumerable: true,\n get: function () {\n return source[key];\n },\n });\n });\n\n return dest;\n};\n\nexports.export = function (dest, destName, get) {\n Object.defineProperty(dest, destName, {\n enumerable: true,\n get: get,\n });\n};\n"],"names":[],"version":3,"file":"index.js.map","sourceRoot":"../../../"} \ No newline at end of file +{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6CAAwB;AAAT,SAAS;IACpB,OAAO,CAAC;QACJ,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG;QAChC,MAAM,EAAE,aAAa,EAAE,GAAG,EAAE,GAAG,YAAY,KAAK;QAEhD,IAAI,cAAc;QAClB,MAAM,SAAS,c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,EAAE,CAAC,WAAW;gBACd,qBAAqB;YACzB;QACJ;IACJ;AACJ;AAEA,IAAI,OAAO,WAAW,aAClB,MAAM,CAAC,uBAAuB,GAAG;;;AC5IrC,QAAQ,cAAc,GAAG,SAAU,CAAC;IAClC,OAAO,KAAK,EAAE,UAAU,GAAG,IAAI;QAAC,SAAS;IAAC;AAC5C;AAEA,QAAQ,iBAAiB,GAAG,SAAU,CAAC;IACrC,OAAO,cAAc,CAAC,GAAG,cAAc;QAAC,OAAO;IAAI;AACrD;AAEA,QAAQ,SAAS,GAAG,SAAU,MAAM,EAAE,IAAI;IACxC,OAAO,IAAI,CAAC,QAAQ,OAAO,CAAC,SAAU,GAAG;QACvC,IACE,QAAQ,aACR,QAAQ,gBACR,OAAO,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,MAE3C;QAGF,OAAO,cAAc,CAAC,MAAM,KAAK;YAC/B,YAAY;YACZ,KAAK;gBACH,OAAO,MAAM,CAAC,IAAI;YACpB;QACF;IACF;IAEA,OAAO;AACT;AAEA,QAAQ,MAAM,GAAG,SAAU,IAAI,EAAE,QAAQ,EAAE,GAAG;IAC5C,OAAO,cAAc,CAAC,MAAM,UAAU;QACpC,YAAY;QACZ,KAAK;IACP;AACF","sources":["packages/artplayer-proxy-canvas/src/index.js","node_modules/@parcel/transformer-js/src/esmodule-helpers.js"],"sourcesContent":["export default function artplayerProxyCanvas() {\n return (art) => {\n const { option, constructor } = art;\n const { createElement, def } = constructor.utils;\n\n let animationId = null;\n const canvas = createElement('canvas');\n const ctx = canvas.getContext('2d');\n const video = createElement('video');\n\n const canvasProperties = {};\n const canvasKeys = ['width', 'height'];\n const { propertys, methods, prototypes, events } = constructor.config;\n const videoKeys = [...propertys, ...methods, ...prototypes];\n\n initCanvasProperties();\n proxyVideoToCanvas();\n setupEventListeners();\n setupArtPlayerEvents();\n\n return canvas;\n\n function initCanvasProperties() {\n canvasKeys.forEach((prop) => {\n canvasProperties[prop] = Object.getOwnPropertyDescriptor(HTMLCanvasElement.prototype, prop);\n });\n }\n\n function proxyVideoToCanvas() {\n videoKeys.forEach((key) => {\n if (canvasKeys.includes(key)) {\n def(canvas, key, {\n get() {\n return canvasProperties[key].get.call(this);\n },\n set(value) {\n canvasProperties[key].set.call(this, value);\n },\n });\n } else {\n def(canvas, key, {\n get() {\n const value = video[key];\n return typeof value === 'function' ? value.bind(video) : value;\n },\n set(value) {\n video[key] = value;\n },\n });\n }\n });\n }\n\n function setupEventListeners() {\n setTimeout(() => {\n events.forEach((event) => {\n art.proxy(video, event, (event) => {\n art.emit(`video:${event.type}`, event);\n });\n });\n });\n }\n\n async function draw() {\n try {\n if (typeof createImageBitmap !== 'undefined') {\n const bitmap = await createImageBitmap(video);\n ctx.drawImage(bitmap, 0, 0, canvas.width, canvas.height);\n bitmap.close();\n } else {\n ctx.drawImage(video, 0, 0, canvas.width, canvas.height);\n }\n art.emit('artplayerProxyCanvas:draw', ctx);\n } catch (error) {\n art.emit('artplayerProxyCanvas:error', error);\n }\n }\n\n async function animation() {\n await draw();\n animationId = requestAnimationFrame(animation);\n }\n\n function resize() {\n const player = art.template?.$player;\n if (!player || option.autoSize) return;\n\n const aspectRatio = video.videoWidth / video.videoHeight;\n const containerWidth = player.clientWidth;\n const containerHeight = player.clientHeight;\n const containerRatio = containerWidth / containerHeight;\n\n let canvasWidth, canvasHeight;\n if (containerRatio > aspectRatio) {\n canvasHeight = containerHeight;\n canvasWidth = canvasHeight * aspectRatio;\n } else {\n canvasWidth = containerWidth;\n canvasHeight = canvasWidth / aspectRatio;\n }\n\n canvas.width = canvasWidth;\n canvas.height = canvasHeight;\n\n const paddingLeft = (containerWidth - canvasWidth) / 2;\n const paddingTop = (containerHeight - canvasHeight) / 2;\n\n Object.assign(canvas.style, {\n padding: `${paddingTop}px ${paddingLeft}px`,\n });\n }\n\n function setupArtPlayerEvents() {\n art.on('video:loadedmetadata', async () => {\n canvas.width = video.videoWidth;\n canvas.height = video.videoHeight;\n });\n\n art.on('video:play', () => {\n cancelAnimationFrame(animationId);\n animationId = requestAnimationFrame(animation);\n });\n\n art.on('video:pause', () => {\n cancelAnimationFrame(animationId);\n });\n\n art.on('resize', () => {\n resize();\n draw();\n });\n\n art.on('destroy', () => {\n cancelAnimationFrame(animationId);\n });\n }\n };\n}\n\nif (typeof window !== 'undefined') {\n window['artplayerProxyCanvas'] = artplayerProxyCanvas;\n}\n","exports.interopDefault = function (a) {\n return a && a.__esModule ? a : {default: a};\n};\n\nexports.defineInteropFlag = function (a) {\n Object.defineProperty(a, '__esModule', {value: true});\n};\n\nexports.exportAll = function (source, dest) {\n Object.keys(source).forEach(function (key) {\n if (\n key === 'default' ||\n key === '__esModule' ||\n Object.prototype.hasOwnProperty.call(dest, key)\n ) {\n return;\n }\n\n Object.defineProperty(dest, key, {\n enumerable: true,\n get: function () {\n return source[key];\n },\n });\n });\n\n return dest;\n};\n\nexports.export = function (dest, destName, get) {\n Object.defineProperty(dest, destName, {\n enumerable: true,\n get: get,\n });\n};\n"],"names":[],"version":3,"file":"index.js.map","sourceRoot":"../../../"} \ No newline at end of file diff --git a/packages/artplayer-proxy-canvas/src/index.js b/packages/artplayer-proxy-canvas/src/index.js index 2f5340e8d..6c66a246c 100644 --- a/packages/artplayer-proxy-canvas/src/index.js +++ b/packages/artplayer-proxy-canvas/src/index.js @@ -63,9 +63,13 @@ export default function artplayerProxyCanvas() { async function draw() { try { - const bitmap = await createImageBitmap(video); - ctx.drawImage(bitmap, 0, 0, canvas.width, canvas.height); - bitmap.close(); + if (typeof createImageBitmap !== 'undefined') { + const bitmap = await createImageBitmap(video); + ctx.drawImage(bitmap, 0, 0, canvas.width, canvas.height); + bitmap.close(); + } else { + ctx.drawImage(video, 0, 0, canvas.width, canvas.height); + } art.emit('artplayerProxyCanvas:draw', ctx); } catch (error) { art.emit('artplayerProxyCanvas:error', error); diff --git a/packages/artplayer-proxy-canvas/types/artplayer-proxy-canvas.d.ts b/packages/artplayer-proxy-canvas/types/artplayer-proxy-canvas.d.ts index afb1e6633..2c802f985 100644 --- a/packages/artplayer-proxy-canvas/types/artplayer-proxy-canvas.d.ts +++ b/packages/artplayer-proxy-canvas/types/artplayer-proxy-canvas.d.ts @@ -3,8 +3,4 @@ import type Artplayer from 'artplayer'; export = artplayerProxyCanvas; export as namespace artplayerProxyCanvas; -type Option = (video: HTMLVideoElement, url: String, art: Artplayer) => void; - -type Result = HTMLCanvasElement; - -declare const artplayerProxyCanvas: (option: Option) => (art: Artplayer) => Result; +declare const artplayerProxyCanvas: () => (art: Artplayer) => HTMLCanvasElement;