Documentation Index
Fetch the complete documentation index at: https://mintlify.com/TextAliveJp/textalive-app-api/llms.txt
Use this file to discover all available pages before exploring further.
What is a Timer?
TheTimer interface is the bridge between the audio engine and the Player.
When the player needs to start, pause, stop, or seek audio it calls methods on
the active Timer instance. In return, the timer calls back into the player
through the updater function to report the current playback position.
This design means you can swap out the audio backend entirely — for example,
to drive the player from a Web Audio API clock, a video element, or a
test harness — without changing any of your app code.
Timer interface
Properties
| Property | Type | Description |
|---|---|---|
isPlaying | boolean | true when the timer is actively advancing the playback position |
position | number | Current playback position in milliseconds. Timer implementations must compute this in real time; it is the most precise position source available |
wait | number | Desired interval between calls to the updater callback in milliseconds |
There are three position sources in the API:
timer.position (most
precise, real-time), player.mediaPosition (updated periodically by the
timer), and player.videoPosition (updated after each rendered frame).
Use timer.position when you need sub-frame accuracy.Methods
| Method | Description |
|---|---|
initialize(options) | Called once during video loading. The timer should set up its audio element here and resolve when ready |
play() | Start playback from the current position |
pause() | Pause playback; position stays at the current value |
stop() | Pause and seek back to position 0 |
seek(position) | Jump to position milliseconds |
dispose() | Release all resources held by this timer |
TimerInitOptions
PlayerMediaPositionUpdateFunction
updater callback is called by your timer on a recurring schedule (every
wait milliseconds). Pass the current playback position in milliseconds and
await the resolved value, which is the position after any adjustments the
player applied (e.g. clamping to song bounds). Your timer loop should use the
resolved value when scheduling the next tick.
BasicTimer
BasicTimer is the simplest Timer implementation bundled with the SDK. It:
- Does not embed any audio element, so no sound plays
- Advances position using
requestAnimationFrame/setTimeout - Is useful for debugging visual animations without needing a media source
BasicTimer has no audio dependency, onTimerReady fires as soon as
the video object is built, and you can call player.requestPlay() immediately
after onVideoReady.
SongleTimer
SongleTimer is the full-featured timer that embeds a Songle audio player.
It is the default timer used when you do not pass timer in PlayerOptions.
SongleTimer is backed by the optional peer dependency songle-api. You do
not need to install or import songle-api manually — the timer loads it
automatically via dynamic import() or a <script> tag injection.
SongleTimer options
accessToken and secretToken enables Songle Sync, which
synchronises playback position across multiple clients in real time.
After onTimerReady fires you can access the underlying Songle Player
instance via (player.timer as SongleTimer).songlePlayer if you need to
call Songle-specific APIs directly.
Implementing a custom Timer
If you need to synchronise TextAlive with an external clock (e.g. a<video>
element or a Web Audio API context), implement the Timer interface:
Choosing a timer
- No audio (debugging)
- Songle audio (production)
- Songle Sync (multi-device)
BasicTimer when you want to iterate on visual animations quickly
without worrying about audio loading.Full type reference: /api/timer