Skip to content

fb.state Playback State Mirror

fb.state is a plain mutable state object that the SDK keeps synchronized through playback events. It is convenient for imperative UI reads and polling without issuing an API call for every update.

Properties

PropertyTypeDescription
volumenumberCurrent output volume on a linear 0-100 scale
isPlayingbooleantrue only when playback state is 'playing'; paused and stopped states are false
currentTrackTrackInfo | nullMost recently announced now-playing track. Initially null; stopping playback does not clear it
positionnumberCurrent playback position in seconds

Automatic Updates

fb.state listens to these events:

EventUpdated fields
playback:stateChangedUpdates isPlaying from state and updates position when present
playback:trackChangedReplaces currentTrack and sets isPlaying = true
playback:stoppedSets isPlaying = false and position = 0
playback:volumeChangedUpdates volume when present
playback:timeUpdates position when present

Examples

Basic Reads

javascript
console.log(fb.state.isPlaying);     // true
console.log(fb.state.volume);        // 80
console.log(fb.state.position);      // 42.5
console.log(fb.state.currentTrack);  // {title, artist, album, ...}

Polling UI Updates

javascript
setInterval(() => {
    document.getElementById('playing').textContent = fb.state.isPlaying ? '▶' : '⏸';
    document.getElementById('position').textContent = Math.floor(fb.state.position) + 's';
}, 500);

Reading State from an Event Handler

javascript
// The SDK updates state before consumer handlers run for this event.
fb.on('playback:trackChanged', () => {
    const track = fb.state.currentTrack;
    if (track) document.title = `${track.title} - ${track.artist}`;
});

State semantics

fb.state is a mutable snapshot, not a Proxy or framework-reactive object. Subscribe through fb.on() for change notifications. Use APIs such as fb.player.getState() or fb.player.getPosition() when an authoritative value is required on demand.

SMP compatibility layer

fb.state tracks only these four playback fields. For the broader cached state used by the SMP compatibility layer, including playlists and configuration, use window.smp.cache; see SMP Compatibility.