Implement a JavaScript frame player controller
Company: Verkada
Role: Software Engineer
Category: Software Engineering Fundamentals
Difficulty: medium
Interview Round: Technical Screen
You are given a skeleton for a frame-by-frame browser media player. Implement a JavaScript controller that:
- Jumps to any frame by index.
- Starts and pauses autoplay at a configurable frames-per-second (FPS).
- Exposes methods: play(), pause(), seek(frameIndex), setFPS(fps), currentFrame(), isPlaying().
- Uses setTimeout or setInterval correctly to schedule frames, handles timer drift, and prevents overlapping timers.
- Encapsulates internal state via closures and cleans up timers/listeners to avoid memory leaks.
Explain your design and time-scheduling strategy, compare setTimeout vs setInterval (and optionally requestAnimationFrame) for this use case, and describe how you would handle edge cases (seeking while playing, invalid indices, reaching the last frame, resuming after pause). Provide pseudocode or tests showing expected behavior.
Quick Answer: Implement a JavaScript frame player controller evaluates requirements, assumptions, structured reasoning, trade-offs, and verification in a realistic interview setting. A strong answer states assumptions, handles edge cases, explains trade-offs, and shows how to validate the result clearly.