nowPlaying Module
Read active media metadata and control playback in Novadesk.
The nowPlaying module is exported from the system module.
import { nowPlaying } from "system";Table of Contents
nowPlaying.stats()
Returns current media session details.
Return Value
- Type:
object - Description: Contains:
available(boolean)player(string)artist(string)album(string)title(string)thumbnail(string): Cached thumbnail image path (empty string if unavailable).duration(number): Track duration in seconds.position(number): Current playback position in seconds.progress(number): Playback progress (0-100).state(number):0stopped/unknown,1playing,2paused.status(number):0closed,1opened.shuffle(boolean)repeat(boolean):truewhen repeat mode is notnone.
INFO
stats() always returns an object. When no active media session exists, fields are default/empty and available is false.
nowPlaying.backend()
Returns active now-playing backend name.
Return Value
- Type:
string - Description:
"winrt"when the WinRT now-playing backend is enabled."disabled"when backend support is not built/enabled.
nowPlaying.play()
Requests playback start on the active media session.
Return Value
- Type:
boolean - Description:
- Returns
truewhen the now-playing backend is enabled and the action is queued. - Returns
falsewhen backend is disabled.
- Returns
nowPlaying.pause()
Requests pause on the active media session.
Return Value
- Type:
boolean - Description:
- Returns
truewhen the now-playing backend is enabled and the action is queued. - Returns
falsewhen backend is disabled.
- Returns
nowPlaying.playPause()
Requests play/pause toggle on the active media session.
Return Value
- Type:
boolean - Description:
- Returns
truewhen the now-playing backend is enabled and the action is queued. - Returns
falsewhen backend is disabled.
- Returns
nowPlaying.stop()
Requests playback stop on the active media session.
Return Value
- Type:
boolean - Description:
- Returns
truewhen the now-playing backend is enabled and the action is queued. - Returns
falsewhen backend is disabled.
- Returns
nowPlaying.next()
Requests skip to the next item in the active media session.
Return Value
- Type:
boolean - Description:
- Returns
truewhen the now-playing backend is enabled and the action is queued. - Returns
falsewhen backend is disabled.
- Returns
nowPlaying.previous()
Requests skip to the previous item in the active media session.
Return Value
- Type:
boolean - Description:
- Returns
truewhen the now-playing backend is enabled and the action is queued. - Returns
falsewhen backend is disabled.
- Returns
nowPlaying.setPosition(value[, isPercent])
Sets playback position.
Parameters
value- Type:
number - Description: Position in seconds by default, or percent when
isPercentistrue.
- Type:
isPercent- Type:
boolean - Required: No
- Default:
false - Description:
trueto interpretvalueas0-100percent of track duration.
- Type:
Return Value
- Type:
boolean - Description:
- Returns
truewhen backend is enabled and action is queued. - Returns
falsewhen backend is disabled.
- Returns
INFO
When isPercent is true, the effective seek time is computed from current track duration. Resulting position is clamped to valid bounds.
nowPlaying.setShuffle(enabled)
Sets shuffle mode.
Parameters
enabled- Type:
boolean
- Type:
Return Value
- Type:
boolean - Description:
truewhen backend is enabled; otherwisefalse.
nowPlaying.toggleShuffle()
Toggles shuffle mode.
Return Value
- Type:
boolean - Description:
truewhen backend is enabled; otherwisefalse.
nowPlaying.setRepeat(mode)
Sets repeat mode.
Parameters
mode- Type:
number - Description: Repeat mode code:
0: none1: track (repeat one)2: list (repeat all)
- Type:
Return Value
- Type:
boolean - Description:
truewhen backend is enabled; otherwisefalse.
Error Behavior
nowPlaying.setPosition(value[, isPercent])throws a type error whenvalueis not numeric.nowPlaying.setRepeat(mode)throws a type error whenmodeis not numeric.
Example
import { nowPlaying } from "system";
console.log("backend:", nowPlaying.backend());
const stats = nowPlaying.stats();
console.log("available:", stats.available);
console.log("player:", stats.player, "title:", stats.title, "progress:", stats.progress + "%");
nowPlaying.playPause();
nowPlaying.setShuffle(true);
nowPlaying.setRepeat(2); // repeat all
nowPlaying.setPosition(50, true); // seek to 50%