ON THIS PAGE

This page describes how to use two advanced BrightAuthor features: custom autorun plugins and parser scripts. These instructions assume a certain level of familiarity with BrightScript. This is not a comprehensive guide to writing custom scripts for BrightAuthor; rather, it is meant to provide a general outline and best practices for writing those scripts.

BrightAuthor Autorun Plugins

Plugins allow you to add script extensions to a standard presentation autorun. Plugins have two primary benefits over custom autoruns: They can be easily inserted into multiple presentations, including newer and older versions of the same presentation; and they are not dependent on a certain autorun or firmware version, greatly reducing the complexity involved in updating custom BrightScript deployments.

BrightAuthor plugins can be added to presentations in BrightAuthor 3.7 or later.

To designate one or more custom plugins for a BrightAuthor presentation, navigate to File > Presentation Properties > Autorun. Click the Add Script Plugin button, give the plugin a name (which must be the same as the <plugin_name> described in the initialization function below), and click the Browse button to locate and select a .brs file to use as a plugin.

Plug-in scripts must include an initialization function in the form of <plugin_name>_Initialize(). This initialization function is passed three parameters:

To process events, the plugin script must provide a ProcessEvent() function that is a member of the associative array returned by the initialization function described above. The ProcessEvent() function is passed a single event object. The function then returns a Boolean indicating whether or not the autorun should continue processing the event object: The function will return True if it handles the event and the standard autorun should not continue processing the event.

The associative array that defines the object must also include an objectName entry that defines the name of the object.

The following is an example of a script plugin file named “pizza.brs”:

Function pizza_Initialize(msgPort As Object, userVariables As Object, o As
Object)

    print "pizza_Initialize - entry"
    print "type of msgPort is ";type(msgPort)
    print "type of userVariables is ";type(userVariables)

    PizzaBuilder = newPizzaBuilder(msgPort, userVariables)

    return PizzaBuilder

End Function

Function newPizzaBuilder(msgPort As Object, userVariables As Object)

    PizzaBuilder = { }
    PizzaBuilder.msgPort = msgPort
    PizzaBuilder.userVariables = userVariables
    PizzaBuilder.objectName = "PizzaBuilder_object"

    PizzaBuilder.ProcessEvent = pizza_ProcessEvent

    return PizzaBuilder

End Function

Function pizza_ProcessEvent(event As Object)

    print "pizza_ProcessEvent - entry"
    print "type of m is ";type(m)
    print "type of event is ";type(event)

' swallows timer events - telling the autorun not to process them
    if type(event)= "roTimerEvent" then
       return true
    else
       return false
    endif

End Function

Receiving a Plugin Message

The following example code shows how to write a script that receives a Send Plugin Message Command from the autorun. This code listens for a message sent to the plugin named “Pizza” and then prints the message:

Function pizza_ProcessEvent(event As Object)

    print "pizza_ProcessEvent - entry"
    print "type of m is ";type(m)
    print "type of event is ";type(event)

    if type(event) = "roAssociativeArray" then
        if type(event["EventType"]) = "roString"
            if event["EventType"] = "SEND_PLUGIN_MESSAGE" then
                if event["PluginName"] = "Pizza" then
                    pluginMessage$ = event["PluginMessage"]
                    print "received pluginMessage ";pluginMessage$
                    return true
                endif
            endif
        endif
    endif

    return false

End Function


Sending a Plugin Message

The following example code shows how to write a script that sends a message string to trigger a Plugin Message event.

print "pizza_ProcessEvent - entry"
    print "type of m is ";type(m)
    print "type of event is ";type(event)

    if type(event) = "roTimer" then

        pluginMessageCmd = CreateObject("roAssociativeArray")
        pluginMessageCmd["EventType"] = "EVENT_PLUGIN_MESSAGE"
        pluginMessageCmd["PluginName"] = "Pizza"
        pluginMessageCmd["PluginMessage"] = "toppings"
        m.msgPort.PostMessage(pluginMessageCmd)
        return true

    endif

    return false

End Function

Parser Scripts – RSS

Parser scripts allow you to manipulate data sets from incoming RSS feeds. You can create RSS parser scripts for a wide array of system and presentation functions. You can designate a parser for an RSS feed by navigating to File > Presentation Properties > Data Feeds in BrightAuthor.

The parser file must have a .brs extension.

The following parameters can be used with an RSS parser subroutine:

The following piece of example code can be used to parse RSS text:

        xml = CreateObject("roXMLElement")
        if not xml.Parse(ReadAsciiFile(xmlFileName$)) then
               print "xml read failed"
        else
               if type(xml.channel.item) = "roXMLList" then
                       index% = 0
                       for each itemXML in xml.channel.item
                               itemsByIndex.push(stri(index%) + " - " + itemXML.description.GetText())
                               index% = index% + 1
                       next
               endif
        endif

end Sub

Parser Scripts – MRSS

You can use a script to parse non-MRSS feeds and provide the data in a format that can be used by Media RSS Feed states in BrightAuthor. To designate a parser for an MRSS feed, navigate to File > Presentation Properties > Data Feeds in BrightAuthor.

The parser file must have a .brs extension.

The following parameters can be used with an MRSS parser subroutine:

Items Array Specification

The parser script should add associative arrays to the items array–each associative array represents a single media item to be played back. The order of items in the array specifies the order of playback.

Each associative array consists of one or more key-value pairs. All values must be strings–including numerical values. The following table outlines accepted key-value pairs:

KeyValueExampleNotes
urlA download URL for the file"www.brightsign.biz/images/myfeedpic1.jpg"Required – The item will be ignored if this value is not present.
mediumvideo | image | audio | document"video"Suggested – If the medium and type values are not present, the medium value will default to "image".
typevideo/*, audio/*, image/*, text/html, application/widget"video/*"Suggested – If the medium and type values are not present, the type value will default to "image/*".
durationThe display duration in seconds"30"Optional – This value applies to images only, and has no effect on other media types. If not specified, this value defaults to "15".
titleThe value for the MRSS Title field"myfeedpic1"Optional
descriptionThe value for the MRSS Description field"$5.99"Optional
sizeThe size of the file in bytes"942061"Optional
guidA unique value for the file"ab05caf"Optional – When this value changes, the player will re-download the file.
mrssCustomFieldsAn associative array of arbitrary key-value pairs{key1:"custom field A", key2:"custom field B"}Optional – Use this associative array to include custom MRSS fields.

Metadata Specification

The metadata object is an empty associative array when the parser subroutine is entered. This associative array can accept optional key-value pairs that represent properties for the entire feed. All values must be strings–including numerical values. The following table outlines accepted key-value pairs:

KeyValueExampleNotes
titleA title for the feed"myfeed1"
ttlThe time-to-live in minutes"5"This value represents how long the feed will be stored (whether it's utilized by the presentation or not) before being refreshed. The user will also set an Update Interval when adding the Data Feed to the BrightAuthor presentation; if the ttl value is specified, the presentation will use the lesser of the two values to determine the refresh frequency.