Skip to content

Instantly share code, notes, and snippets.

View Jagathishrex's full-sized avatar
🎯
Focusing

Jagathishrex

🎯
Focusing
View GitHub Profile
request.onload = function() {
if(request.status === 200) {
console.log("Response from server = ", request.response);
} else {
consle.log( request.status , ":", request.statusText ); // 500: Internal server error
}
}
let isPiPSupported = 'pictureInPictureEnabled' in document,
isPiPEnabled = document.pictureInPictureEnabled;
if (!isPiPSupported) {
console.log('The Picture-in-Picture Web API is not available.');
}
else if (!isPiPEnabled) {
console.log('The Picture-in-Picture Web API is disabled.');
} else {
console.log("PiP supported");
}
var pipWindow;
video.addEventListener('enterpictureinpicture', function(event) {
pipWindow = event.pictureInPictureWindow;
console.log(`> Window size is ${pipWindow.width}x${pipWindow.height}`);
pipWindow.addEventListener('resize', onPipWindowResize);
});
video.addEventListener('leavepictureinpicture', function(event) {
pipWindow.removeEventListener('resize', onPipWindowResize);
});
<html>
<head>
<title>Picture-in-Picture</title>
</head>
<body>
<video id="videoElement" controls="true" src="https://archive.org/download/BigBuckBunny_124/Content/big_buck_bunny_720p_surround.mp4"> </video>
<button id="PiP"> Enable Floating Video </button>
<script>
let video = document.getElementById('videoElement');
let toggleBtn = document.getElementById('PiP');
// image as dataURL
let jpeg = canvas.toDataURL('image/jpg'); // 0.92
let webp = canvas.toDataURL('image/webp', 0.5);
//zip
let jsZip = new JSZip();
let folder = jsZip.folder("images");
let baseString = getBase64String(jpeg);
folder.file("image1.jpeg", baseString, {base64 : true});
let baseString2 = getBase64String(webp);
folder.file("image2.webp", baseString2, {base64 : true});
function getBase64String(dataURL) {
var idx = dataURL.indexOf('base64,') + 'base64,'.length;
return dataURL.substring(idx);
}
let jsZip = new JSZip();
let jpeg = canvas.toDataURL('image/jpg'); // 0.92
let webp = canvas.toDataURL('image/webp', 0.5);
var download = function(href, name){
var link = document.createElement('a');
link.download = name;
link.style.opacity = "0";
document.append(link);
link.href = href;
link.click();
link.remove();
}
download(png, "image.png");
var download = function(href, name){
var link = document.createElement('a');
link.download = name;
link.style.opacity = "0";
document.append(link);
link.href = href;
link.click();
link.remove();
}
download(png, "image.png");