Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 13 Next »

 Table of Contents

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.

Overview

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.

  • They are not dependent on a certain autorun or firmware version, greatly reducing the complexity involved in updating custom BrightScript deployments.

BrightAuthor Autorun Plugins

Note

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

To designate one or more custom plugins in BrightAuthor:

  1. Navigate to File > Presentation Properties > Autorun.

  2. Select the Add Script Plugin button

  3. Give the plugin a name (which must be the same as the <plugin_name> described in the initialization function below),

  4. Select the Browse button to locate and select a .brs file to use as a plugin.

Plugin Structure

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

  • msgPort As Object

  • userVariables As Object

  • o As Object: This is the .bsp associative array from the autorun. It is required for the initialization function to return an associative array.

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.

Important

The parser file must have a .brs extension.

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

  • xmlFileName$: The name of the XML file. This value is provided by the presentation autorun.

  • itemsByIndex: An array of the descriptions. The script should fill in this array if the Live Text object is using the “item index” to display items from this feed.

  • itemsByTitle: An associative array of titles, descriptions. The script should fill in this array if a Live Text object is using the “item title” to display items from this feed.

  • userVariables: An associative array of current User Variables (which are provided by the autorun). This is provided in case you want to analyze or modify the User Variables.

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.

Important

The parser file must have a .brs extension.

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

  • fileName$: The name of the feed file to be parsed. This value is provided by the presentation autorun.

  • items: An array of associative arrays representing MRSS items to be played by Media RSS Feed states. This array is empty upon entry to the parser subroutine and should be filled by the script. When the parser subroutine exits, the autorun will supply the data in the array to Media RSS Feed states for playback. See the Item Array Specification section below for a list of associative-array parameters.

  • metadata: An associative array containing optional metadata items pertaining to the entire playlist/feed.

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:

Key

Value

Example

Notes

url

A download URL for the file

"www.brightsign.biz/images/myfeedpic1.jpg"

Required – The item will be ignored if this value is not present.

medium

video | image | audio | document

"video"

Suggested – If the medium and type values are not present, the medium value will default to "image".

type

video/*, audio/*, image/*, text/html, application/widget

"video/*"

Suggested – If the medium and type values are not present, the type value will default to "image/*".

duration

The 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".

title

The value for the MRSS Title field

"myfeedpic1"

Optional

description

The value for the MRSS Description field

"$5.99"

Optional

size

The size of the file in bytes

"942061"

Optional

guid

A unique value for the file

"ab05caf"

Optional – When this value changes, the player will re-download the file.

mrssCustomFields

An 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:

Key

Value

Example

Notes

title

A title for the feed

"myfeed1"


ttl

The 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.


  • No labels