BrightScript Quick Reference#

Quick lookup for BrightScript objects, methods, and functions.

Core Objects#

System Objects#

ObjectPurposeKey Methods
roDeviceInfoDevice informationGetModel(), GetDeviceUniqueId(), GetVersion()
roSystemTimeSystem clockSetTimeZone(), GetLocalDateTime()
roDateTimeDate/time operationsToIsoString(), AsSeconds(), GetYear()
roMessagePortEvent queueUsed with wait()
roTimerTimed eventsSetElapsed(), Start(), Stop(), GetIdentity()

Media Objects#

ObjectPurposeKey Methods
roVideoPlayerVideo playbackPlayFile(), Pause(), Resume(), Stop(), Seek()
roAudioPlayerAudio playbackPlayFile(), Stop(), SetVolume()
roImagePlayerImage displayDisplayFile(), SetTransition()
roVideoModeDisplay settingsSetMode(), GetResX(), GetResY()

Network Objects#

ObjectPurposeKey Methods
roUrlTransferHTTP clientSetUrl(), GetToString(), PostFromString()
roNetworkConfigurationNetwork configSetDHCP(), SetIP4Address(), Apply()
roHttpServerHTTP serverAddGetFromEvent(), SetPort()
roDatagramSocketUDP socketSend(), SetAddress()
roStreamSocketTCP socketConnect(), Send(), Receive()

Storage Objects#

ObjectPurposeKey Methods
roReadFileRead filesReadLine(), AtEof()
roCreateFileCreate filesSendLine(), Flush()
roAppendFileAppend filesSendLine(), Flush()
roByteArrayBinary dataReadFile(), WriteFile(), ToBase64String()
roStorageInfoStorage infoGetDriveTotalSize(), GetDriveFreeSpace()
roRegistrySectionRegistry accessRead(), Write(), Flush(), Exists()

Hardware Objects#

ObjectPurposeKey Methods
roGpioControlPortGPIO controlSetOutputState(), SetWholeState()
roSerialPortSerial commSendLine(), GetLine()

HTML Objects#

ObjectPurposeKey Methods
roHtmlWidgetHTML displaySetPort(), PostJSMessage(), SetUrl()

Global Functions#

File Operations#

content$ = ReadAsciiFile(filename$)
WriteAsciiFile(filename$, content$)
files = ListDir(directory$)
files = MatchFiles(directory$, pattern$)
CreateDirectory(path$)
DeleteFile(path$)
MoveFile(source$, dest$)
CopyFile(source$, dest$)

String Functions#

length = Len(string$)
upper$ = UCase(string$)
lower$ = LCase(string$)
left$ = Left(string$, count)
right$ = Right(string$, count)
mid$ = Mid(string$, start, length)

Type Conversion#

str$ = Str(number)           ' Number to string (with space)
str$ = number.ToStr()        ' Number to string (no space)
num = Val(string$)           ' String to number
json$ = FormatJson(object)   ' Object to JSON
object = ParseJson(json$)    ' JSON to object

Utility#

type$ = type(variable)       ' Get type name
sleep(milliseconds)          ' Pause execution
RebootSystem()               ' Reboot player

Event Types#

Event TypeSourceKey Methods
roTimerEventroTimerGetSourceIdentity()
roVideoEventroVideoPlayerGetInt() (event code)
roAudioEventroAudioPlayerGetInt()
roUrlEventroUrlTransferGetResponseCode(), GetString()
roHttpEventroHttpServerGetMethod(), GetUrl()
roGpioButtonroGpioControlPortGetInt() (button ID)
roHtmlWidgetEventroHtmlWidgetQueryData()

Video Event Codes#

CodeEvent
1Start of stream
3Playing
4Paused
5Resumed
8Media ended
19Failed
30Time hit

HTTP Response Codes#

CodeMeaning
200OK
201Created
204No Content
301/302Redirect
400Bad Request
401Unauthorized
403Forbidden
404Not Found
500Server Error
< 0BrightSign error

Common Patterns#

Event Loop#

msgPort = CreateObject("roMessagePort")
while true
    msg = wait(0, msgPort)
    if type(msg) = "roVideoEvent" then
        HandleVideoEvent(msg)
    end if
end while

Factory Function#

Function newPlayer() As Object
    return {
        video: CreateObject("roVideoPlayer"),
        play: Function(file$) As Void
            m.video.PlayFile(file$)
        End Function
    }
End Function

Configuration Load#

json$ = ReadAsciiFile("SD:/config.json")
config = ParseJson(json$)
if config = invalid then config = {}