the screenshot I took in Wechat"s development tool is OK, but the screenshot on the phone has become completely transparent.
I guess it"s the first frame of the video
screenshot of Wechat"s development tool
my code:
JS:
function captureImage(video) {
var scale=1
var canvas = document.createElement("canvas");
var vw=$(video).width()
var vh=$(video).height()
console.log(vw,vh)
canvas.width = vw* scale;
canvas.height = vh* scale;
canvas.getContext("2d").drawImage(video, 0, 0, canvas.width, canvas.height);
var img = document.createElement("img");
img.className="poster"
img.src = canvas.toDataURL("image/png");
$(video).prop("poster",canvas.toDataURL("image/png"))
};
HTML tag:
<video src="./show.mp4" class="video" onloadeddata="captureImage(this)"></video>