Player APIs (BrightScript & Ja...
JavaScript APIs
audio
12min
the audio object is a javascript object for use with ronodejs that allows the playback of audio by replicating functionality from the html5 audio element audio idl interface audio { // error state readonly attribute mediaerror error; // network state attribute string src; readonly attribute string currentsrc; readonly attribute unsigned short networkstate; const unsigned short network empty = 0; const unsigned short network idle = 1; const unsigned short network loading = 2; const unsigned short network no source = 3; void load(); string canplaytype(string type); // ready state readonly attribute unsigned short readystate; const unsigned short have nothing = 0; const unsigned short have metadata = 1; const unsigned short have current data = 2; const unsigned short have future data = 3; const unsigned short have enough data = 4; readonly attribute boolean seeking; // playback state attribute double currenttime; readonly attribute double duration; readonly attribute boolean paused; attribute double defaultplaybackrate; attribute double playbackrate; readonly attribute boolean ended; attribute boolean autoplay; attribute boolean loop; void play(); void pause(); void setsyncparams(string domain, string sync id, string iso timestamp); // controls attribute double volume; attribute boolean muted; // brightsign extensions attribute string pcmaudio; attribute string compaudio; attribute int x bs stream timeout; attribute string x bs audio mode; // present but unimplemented attribute string preload; readonly attribute timeranges buffered; readonly attribute double initialtime; readonly attribute date startoffsettime; attribute boolean controls; readonly attribute timeranges played; readonly attribute timeranges seekable; readonly attribute texttrack\[] tracks; mutabletexttrack addtrack(string kind, optional string label, optional string language); }; object creation to create an audio object, first load the brightsign/audio module using the require() method then create an instance of the audio class using the following example var audio class = require("@brightsign/audio"); var audio player = new audio class(); audio use this interface to create audio objects event seeked this event is fired when media loops back to the start methods load() void load() triggers processing of the src load starts up playback to the point of being ready to play the first frame if autoplay is set, then it also starts playback readystate and networkstate are altered, and multiple events fire as playback starts canplaytype() string canplaytype(string type) returns whether the passed mime type can be displayed on the brightsign player play() void play() starts or resumes playback pause() void pause() pauses playback setsyncparams() void setsyncparams(string domain, string sync id, string iso timestamp) this brightsign extension is documented on bssyncmanager docid\ dqnx2ot2tdkxynmrglncp audio parameters src string string contains the url of a media resource to use in the element only file urls are supported currently, including relative urls to the current script and a file /// uri with an absolute filesystem path on the player the url returned when reading this value back is always absolute with file protocol on the front currentsrc string string contains the url of the media resource in use by the element networkstate unsigned short unsigned short an enum that indicates the current state of the fetching of media this attribute moves through the states as src is selected and playback begins, but because support is currently for files only, it is not as dynamic as when used with http possible values are network empty = 0, network idle, network loading, network no source readystate unsigned short unsigned short indicates the readiness state of media this attribute moves through the states as src is selected and playback begins possible values are have nothing = 0, have metadata, have current data, have future data, have enough data seeking boolean boolean indicates if the media is seeking to a new position currenttime double double specifies the current playback time in seconds as a floating point currently seeking is not supported, and setting this attribute has no effect if playback is completed, this returns the same value as duration duration double double specifies the current duration of the media in seconds as a floating point paused boolean boolean reflects whether the media playback is currently paused defaultplaybackrate double double this cannot be set to anything other than 1 0, and always returns 1 0 (only normal speed playback is supported) playbackrate double double this cannot be set to anything other than 1 0, and always returns 1 0 (only normal speed playback is supported) ended boolean boolean reflects where the media playback has reached the end of the media autoplay boolean boolean indicates whether playback should automatically begin when media is available to play without interruption loop boolean boolean sets whether the playback should loop or not the value is used when load is called setting it once playback has started will have no effect volume double double controls the volume of playback muted boolean boolean controls the muting and unmuting of the audio pcmaudio string string route decoded pcm audio to the outputs in the string outputs available are analog , earc , or a usb output (for example, usb\ a 0 ) multiple outputs can be specified by using a semi colon delimeter (for example, earc; analog ) compaudio string string routes compressed audio direct to earc without decoding can be set to earc only x bs stream timeout int int controls timeouts when streaming x bs audio mode string string controls the downmix of audio to mono possible values are monoleftmixdown , monorightmixdown , and the default which is stereo using this, two audio players can output to a single stereo output, one to the left channel, and the other to the right channel unimplemented methods and properties preload buffered initialtime startoffsettime controls played seekable tracks examples const audio class = require("@brightsign/audio"); let audio player = new audio class(); audio player src = "/storage/sd/file mp4" audio player volume = 5; audio player load(); audio player play(); let setupaudio = (audio, setupobj) => { for (let \[key, val] of object entries(setupobj)) { audio\[key] = val; } } let interval = setinterval(()=>{}, 10000); const audio class = require("@brightsign/audio"); let audio = new audio class(); let settings = { src '/storage/sd/file mp4', autoplay true, loop false, volume 5, pcmaudio "analog" }; setupaudio(audio, settings); audio load(); audio addeventlistener("ended", () => { audio src = ''; audio = null; clearinterval(interval); process exit(0); });