@@ -11,9 +11,9 @@ export function clear(store) {
11
11
store . space = [ ] ;
12
12
}
13
13
14
- function framing ( store ) {
15
- const { video , dialogues, actives } = store ;
16
- const vct = video . currentTime - store . delay ;
14
+ function framing ( store , mediaTime ) {
15
+ const { dialogues, actives } = store ;
16
+ const vct = mediaTime - store . delay ;
17
17
for ( let i = actives . length - 1 ; i >= 0 ; i -= 1 ) {
18
18
const dia = actives [ i ] ;
19
19
const { end } = dia ;
@@ -31,9 +31,6 @@ function framing(store) {
31
31
( dia . animations || [ ] ) . forEach ( ( animation ) => {
32
32
animation . currentTime = ( vct - dia . start ) * 1000 ;
33
33
} ) ;
34
- if ( ! video . paused ) {
35
- batchAnimate ( dia , 'play' ) ;
36
- }
37
34
actives . push ( dia ) ;
38
35
}
39
36
store . index += 1 ;
@@ -53,27 +50,38 @@ export function createSeek(store) {
53
50
}
54
51
return ( dialogues . length || 1 ) - 1 ;
55
52
} ) ( ) ;
56
- framing ( store ) ;
53
+ framing ( store , video . currentTime ) ;
57
54
} ;
58
55
}
59
56
57
+ function createFrame ( video ) {
58
+ const useVFC = video . requestVideoFrameCallback ;
59
+ return [
60
+ useVFC ? video . requestVideoFrameCallback . bind ( video ) : requestAnimationFrame ,
61
+ useVFC ? video . cancelVideoFrameCallback . bind ( video ) : cancelAnimationFrame ,
62
+ ] ;
63
+ }
64
+
60
65
export function createPlay ( store ) {
66
+ const { video } = store ;
67
+ const [ requestFrame , cancelFrame ] = createFrame ( video ) ;
61
68
return function play ( ) {
62
- const frame = ( ) => {
63
- framing ( store ) ;
64
- store . requestId = requestAnimationFrame ( frame ) ;
69
+ const frame = ( now , metadata ) => {
70
+ framing ( store , metadata ?. mediaTime || video . currentTime ) ;
71
+ store . requestId = requestFrame ( frame ) ;
65
72
} ;
66
- cancelAnimationFrame ( store . requestId ) ;
67
- store . requestId = requestAnimationFrame ( frame ) ;
73
+ cancelFrame ( store . requestId ) ;
74
+ store . requestId = requestFrame ( frame ) ;
68
75
store . actives . forEach ( ( dia ) => {
69
76
batchAnimate ( dia , 'play' ) ;
70
77
} ) ;
71
78
} ;
72
79
}
73
80
74
81
export function createPause ( store ) {
82
+ const [ , cancelFrame ] = createFrame ( store . video ) ;
75
83
return function pause ( ) {
76
- cancelAnimationFrame ( store . requestId ) ;
84
+ cancelFrame ( store . requestId ) ;
77
85
store . requestId = 0 ;
78
86
store . actives . forEach ( ( dia ) => {
79
87
batchAnimate ( dia , 'pause' ) ;
0 commit comments