mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-23 22:01:20 -08:00
add getScreenshotBlobUrl
This commit is contained in:
1 parent
078507356a
commit
965e3e008f
5 files changed
+51
-5
No files matched your search
@@ -50,6 +50,10 @@ class Artplayer extends Emitter {
|
||||
return utils;
|
||||
}
|
||||
|
||||
static get Emitter() {
|
||||
return Emitter;
|
||||
}
|
||||
|
||||
static get DEFAULTS() {
|
||||
return {
|
||||
container: '#artplayer',
|
||||
|
||||
@@ -14,7 +14,7 @@ export default function screenshotMix(art, player) {
|
||||
canvas.width = $video.videoWidth;
|
||||
canvas.height = $video.videoHeight;
|
||||
canvas.getContext('2d').drawImage($video, 0, 0);
|
||||
return canvas.toDataURL('image/png');;
|
||||
return canvas.toDataURL('image/png');
|
||||
} catch (error) {
|
||||
notice.show(error);
|
||||
console.warn(error);
|
||||
@@ -23,6 +23,25 @@ export default function screenshotMix(art, player) {
|
||||
},
|
||||
});
|
||||
|
||||
Object.defineProperty(player, 'getScreenshotBlobUrl', {
|
||||
value: () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
const canvas = document.createElement('canvas');
|
||||
canvas.width = $video.videoWidth;
|
||||
canvas.height = $video.videoHeight;
|
||||
canvas.getContext('2d').drawImage($video, 0, 0);
|
||||
canvas.toBlob(blob => {
|
||||
resolve(URL.createObjectURL(blob));
|
||||
});
|
||||
} catch (error) {
|
||||
notice.show(error);
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
Object.defineProperty(player, 'screenshot', {
|
||||
value: () => {
|
||||
const dataUri = player.getScreenshotDataURL();
|
||||
|
||||
@@ -60,12 +60,12 @@ export function debounce(func, wait, context) {
|
||||
fn.clearTimeout = function ct() {
|
||||
clearTimeout(timeout);
|
||||
};
|
||||
|
||||
|
||||
return fn;
|
||||
}
|
||||
|
||||
export function isObject(item) {
|
||||
return (item && typeof item === 'object' && !Array.isArray(item));
|
||||
return item && typeof item === 'object' && !Array.isArray(item);
|
||||
}
|
||||
|
||||
export function isElement(item) {
|
||||
@@ -179,4 +179,4 @@ export function downloadImage(url, name) {
|
||||
document.body.appendChild(elink);
|
||||
elink.click();
|
||||
document.body.removeChild(elink);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user