File tree 2 files changed +52
-0
lines changed
2 files changed +52
-0
lines changed Original file line number Diff line number Diff line change
1
+ < script >
2
+
3
+ const getMediaTime = ( ) => new Promise ( resolve => {
4
+ const video = document . getElementsByTagName ( 'video' ) [ 0 ] ;
5
+ if ( ! video ) return ;
6
+ video . requestVideoFrameCallback ( ( now , metadata ) => {
7
+ resolve ( metadata . mediaTime ) ;
8
+ } )
9
+ } ) ;
10
+
11
+ window . jumpPrevFrame = async ( ) => {
12
+ const video = document . getElementsByTagName ( 'video' ) [ 0 ] ;
13
+ if ( ! video ) return ;
14
+
15
+ video . currentTime += 1 ;
16
+ video . currentTime -= 1 ;
17
+ const firstMediaTime = await getMediaTime ( ) ;
18
+
19
+
20
+ for ( ; ; ) {
21
+ video . currentTime -= 0.01 ;
22
+ if ( ( await getMediaTime ( ) ) !== firstMediaTime ) {
23
+ break ;
24
+ }
25
+ }
26
+
27
+ }
28
+
29
+ window . jumpNextFrame = async ( ) => {
30
+ const video = document . getElementsByTagName ( 'video' ) [ 0 ] ;
31
+ if ( ! video ) return ;
32
+
33
+
34
+
35
+ video . currentTime += 1 ;
36
+ video . currentTime -= 1 ;
37
+ const firstMediaTime = await getMediaTime ( ) ;
38
+
39
+ for ( ; ; ) {
40
+ video . currentTime += 0.01 ;
41
+ if ( ( await getMediaTime ( ) ) !== firstMediaTime ) break ;
42
+ }
43
+
44
+
45
+ }
46
+ </ script >
47
+
48
+ < video src ="./25fps.mp4 " muted ="true " playsInline ="true " preload ="auto "> </ video >
49
+ < div >
50
+ < button onclick ="jumpPrevFrame() "> PREV_FRAME</ button >
51
+ < button onclick ="jumpNextFrame() "> NEXT_FRAME</ button >
52
+ </ div >
You can’t perform that action at this time.
0 commit comments