Skip to content

Commit 3b45d07

Browse files
committed
Fix+Capture: let be possible to capture the video:not(.webaudio) and the audio visualisation
1 parent 42726e4 commit 3b45d07

File tree

3 files changed

+26
-20
lines changed

3 files changed

+26
-20
lines changed

api/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
var loaded = false;
66

77
window.api = {
8-
version: "0.8.9",
8+
version: "0.8.10",
99
thumbnail: {}
1010
};
1111

event/capture.js

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,45 @@
33
(function() {
44

55
var
6-
video = dom.screenVideo[ 0 ],
7-
canvas = document.createElement( "canvas" ),
8-
ctx = canvas.getContext( "2d" )
6+
canvasCapture = document.createElement( "canvas" ),
7+
ctx = canvasCapture.getContext( "2d" )
98
;
109

1110
dom.ctrlCaptureBtn.click( function() {
1211
var
13-
w = video.videoWidth,
14-
h = video.videoHeight,
15-
sec = api.video.currentTime(),
16-
hr = ~~( sec / 3600 ),
17-
mn = ~~( sec / 60 ) % 60,
18-
sc = sec % 60,
19-
wasPlaying = api.video.isPlaying
12+
w, h,
13+
dur, hr, mn, sc,
14+
file, canvas
2015
;
2116

22-
if ( w && h ) {
17+
if ( api.isLoaded ) {
18+
file = api.playlist.selectedFile();
19+
20+
if ( file.type === "audio" ) {
21+
canvas = dom.screenCanvas[ 0 ];
22+
} else {
23+
canvas = canvasCapture;
24+
w = canvas.width = api.videoElement.videoWidth;
25+
h = canvas.height = api.videoElement.videoHeight;
26+
ctx.drawImage( api.videoElement, 0, 0, w, h );
27+
}
28+
29+
// Write the specific time in the screenshot's name.
30+
// Be careful by not adding any forbidden char like ":>/" etc.
31+
dur = api.video.currentTime();
32+
hr = ~~( dur / 3600 );
33+
mn = ~~( dur / 60 ) % 60;
34+
sc = dur % 60;
2335
if ( mn < 10 ) {
2436
mn = "0" + mn;
2537
}
2638
sc = ( sc < 10 ? "0" : "" ) + sc.toFixed( 2 );
27-
canvas.width = w;
28-
canvas.height = h;
2939

30-
// Pause the video to avoid any conflict and accelerate the screenshot.
31-
api.video.pause();
32-
ctx.drawImage( video, 0, 0, w, h );
3340
dom.ctrlCaptureBtn.attr( {
3441
href: canvas.toDataURL(),
35-
download: api.playlist.selectedFile().name.replace( /\s/g, "_" ) +
42+
download: file.name.replace( /\s/g, "_" ) +
3643
"__at_" + hr + "h" + mn + "m" + sc + "s.png"
3744
});
38-
api.video.playToggle( wasPlaying );
3945
}
4046
});
4147

0 commit comments

Comments
 (0)