Skip to content

Media

Generated from crates/niso-core/include/media.h when the site was built at 7aa23e2.

This is the media section of niso_runtime.h, owned by niso-media and kept in crates/niso-core/include/media.h. The build composes it with the other sections in the order crates/niso-compose/sections.txt gives.

Functions: niso_dom_media_update, niso_dom_media_session_action, niso_media_session_set_metadata, niso_media_session_set_state, niso_media_session_set_position, niso_media_session_take_actions

Media. A host reports its player for a MEDIA op’s node: state 0 loading or buffering, 1 playable (playing if the op says play), 2 paused by the platform (an interruption), 3 ended, 4 failed; the position and duration in seconds, NaN when unknown and infinite for a live stream. The media events it causes fire at the next niso_render_frame.

int32_t niso_dom_media_update(niso_dom* dom, niso_handle node, uint8_t state, double time, double duration);

An action from the platform’s media controls: 0 play, 1 pause, 2 stop, 3 seek backward, 4 seek forward, 5 previous track, 6 next track, 7 seek to seek_time seconds. The page’s handler gets it if it has one (see niso_media_session_take_actions), else play and pause control the element that last started playing.

int32_t niso_dom_media_session_action(niso_dom* dom, uint8_t action, double seek_time);

The page’s media session, for language bindings: the metadata (the artwork URL is resolved against the document), the playback state (0 none: as the playing element says, 1 paused, 2 playing) and the actions it handles (bit n for action n). niso_media_session_set_position is setPositionState(): the duration (infinite for a live stream), playback rate and position in seconds as of now, from which the position advances at the rate while the session plays; a NaN duration clears it. It fails with NISO_TYPE_ERROR for what the Media Session spec rejects: a negative duration, a position outside 0 to the duration, a rate of 0, or a position or rate that is not finite. niso_media_session_take_actions returns the actions due to the page’s handlers since the last call, as bytes valid until the next call into the DOM: u32 count, then per action u8 action and f64 seek time.

int32_t niso_media_session_set_metadata(niso_dom* dom, const char* title, size_t title_len, const char* artist,
size_t artist_len, const char* album, size_t album_len, const char* artwork,
size_t artwork_len);
int32_t niso_media_session_set_state(niso_dom* dom, uint8_t state, uint32_t handled);
int32_t niso_media_session_set_position(niso_dom* dom, double duration, double playback_rate, double position);
int32_t niso_media_session_take_actions(niso_dom* dom, niso_bytes* out);