(deps: PlayerDeps)
| 125 | } |
| 126 | |
| 127 | export function createRuntimePlayer(deps: PlayerDeps): RuntimePlayer { |
| 128 | return { |
| 129 | _timeline: null, |
| 130 | play: () => { |
| 131 | const timeline = deps.getTimeline(); |
| 132 | if (!timeline || deps.getIsPlaying()) return; |
| 133 | const safeDuration = Math.max( |
| 134 | 0, |
| 135 | Number(deps.getSafeDuration?.() ?? safeNum(timeline, "duration", 0)) || 0, |
| 136 | ); |
| 137 | if (safeDuration > 0) { |
| 138 | const currentTime = Math.max(0, safeNum(timeline, "time", 0)); |
| 139 | if (currentTime >= safeDuration) { |
| 140 | safeVoid(timeline, "pause"); |
| 141 | if (typeof timeline.seek === "function") timeline.seek(0, false); |
| 142 | deps.onDeterministicSeek(0); |
| 143 | deps.setIsPlaying(false); |
| 144 | deps.onSyncMedia(0, false); |
| 145 | deps.onRenderFrameSeek(0); |
| 146 | } |
| 147 | } |
| 148 | if (typeof timeline.timeScale === "function") { |
| 149 | timeline.timeScale(deps.getPlaybackRate()); |
| 150 | } |
| 151 | safeVoid(timeline, "play"); |
| 152 | forEachSiblingTimeline(deps.getTimelineRegistry?.(), timeline, (tl) => { |
| 153 | if (typeof tl.timeScale === "function") tl.timeScale(deps.getPlaybackRate()); |
| 154 | safeVoid(tl, "play"); |
| 155 | }); |
| 156 | deps.onDeterministicPlay(); |
| 157 | deps.setIsPlaying(true); |
| 158 | deps.onShowNativeVideos(); |
| 159 | deps.onStatePost(true); |
| 160 | }, |
| 161 | pause: () => { |
| 162 | const timeline = deps.getTimeline(); |
| 163 | if (!timeline) return; |
| 164 | safeVoid(timeline, "pause"); |
| 165 | forEachSiblingTimeline(deps.getTimelineRegistry?.(), timeline, (tl) => { |
| 166 | safeVoid(tl, "pause"); |
| 167 | }); |
| 168 | const time = Math.max(0, safeNum(timeline, "time", 0)); |
| 169 | deps.onDeterministicSeek(time); |
| 170 | deps.onDeterministicPause(); |
| 171 | deps.setIsPlaying(false); |
| 172 | deps.onSyncMedia(time, false); |
| 173 | deps.onRenderFrameSeek(time); |
| 174 | deps.onStatePost(true); |
| 175 | }, |
| 176 | seek: (timeSeconds: number, options?: { keepPlaying?: boolean }) => { |
| 177 | const timeline = deps.getTimeline(); |
| 178 | if (!timeline) return; |
| 179 | const safeTime = Math.max(0, Number(timeSeconds) || 0); |
| 180 | const wasPlaying = deps.getIsPlaying(); |
| 181 | const quantized = seekMasterAndSiblingTimelinesDeterministically( |
| 182 | deps.getTimelineRegistry?.(), |
| 183 | timeline, |
| 184 | safeTime, |
no test coverage detected