mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-20 12:11:20 -08:00
chore: Update artplayer-proxy-canvas to support canvas proxy
This commit is contained in:
1 parent
0f60ea53ae
commit
813528f916
4 files changed
+59
-19
No files matched your search
@@ -11,16 +11,33 @@ export default function artplayerProxyCanvas(callback) {
|
||||
const { propertys, methods, prototypes, events } = constructor.config;
|
||||
const keys = [...propertys, ...methods, ...prototypes];
|
||||
|
||||
const originalCanvasProperties = {};
|
||||
['width', 'height'].forEach((prop) => {
|
||||
originalCanvasProperties[prop] = Object.getOwnPropertyDescriptor(HTMLCanvasElement.prototype, prop);
|
||||
});
|
||||
|
||||
keys.forEach((key) => {
|
||||
def(canvas, key, {
|
||||
get() {
|
||||
const value = video[key];
|
||||
return typeof value === 'function' ? value.bind(video) : value;
|
||||
},
|
||||
set(value) {
|
||||
video[key] = value;
|
||||
},
|
||||
});
|
||||
if (key === 'width' || key === 'height') {
|
||||
def(canvas, key, {
|
||||
get() {
|
||||
return originalCanvasProperties[key].get.call(this);
|
||||
},
|
||||
set(value) {
|
||||
originalCanvasProperties[key].set.call(this, value);
|
||||
video[key] = value;
|
||||
},
|
||||
});
|
||||
} else {
|
||||
def(canvas, key, {
|
||||
get() {
|
||||
const value = video[key];
|
||||
return typeof value === 'function' ? value.bind(video) : value;
|
||||
},
|
||||
set(value) {
|
||||
video[key] = value;
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
setTimeout(() => {
|
||||
@@ -75,7 +92,6 @@ export default function artplayerProxyCanvas(callback) {
|
||||
});
|
||||
|
||||
art.on('video:play', () => {
|
||||
console.log('video:play');
|
||||
cancelAnimationFrame(animationFrame);
|
||||
animationFrame = requestAnimationFrame(drawFrame);
|
||||
});
|
||||
@@ -86,6 +102,12 @@ export default function artplayerProxyCanvas(callback) {
|
||||
|
||||
art.on('resize', resize);
|
||||
|
||||
const destroy = () => {
|
||||
cancelAnimationFrame(animationFrame);
|
||||
};
|
||||
|
||||
art.on('destroy', destroy);
|
||||
|
||||
if (typeof callback === 'function') {
|
||||
callback.call(art, video, option.url, art);
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user