0

Enhanced Sync BrightScript example (roSyncManager)

I had a lot of trouble understanding how Enhanced Synchronization works in BrightScript so I'm sharing this code to help others who want to see a minimal example of how to use roSyncManager.

' LEADER - Minimum example of Enhanced Sync
' Based on: https://brightsign.atlassian.net/wiki/spaces/DOC/pages/370673205/roSyncManager
' - (Assumes that each player already has manual IP and PTP domain set in registry)
' - Insert your filename below!

print "ENHANCED SYNC TEST - LEADER"
' Create a sync manager with default address and port.
aa1=CreateObject("roAssociativeArray")
aa1.Domain = "BS1"
s=CreateObject("roSyncManager", aa1)
p=CreateObject("roMessagePort")
s.SetPort(p)

' Create a video player - we're going to play a seamlessly looped file
v=CreateObject("roVideoPlayer")
v.SetLoopMode(True)

' We're the leader unit - send out a synchronize event saying that we're starting.
' playback 1000ms from now
s.SetMasterMode(True) ' Docs say "SetLeaderMode" but "SetMasterMode" seems to be correct!
msg = s.Synchronize("Blah1", 1000) ' Blah1 is an optional "sync ID" payload to pass to the follower

aa=CreateObject("roAssociativeArray")
aa.Filename = "Sync Test 1 (30sec HD fixed PCM).mov"
aa.SyncDomain = msg.GetDomain()
aa.SyncId = msg.GetId()
aa.SyncIsoTimestamp = msg.GetIsoTimestamp()

ok = v.PlayFile(aa)
if ok then
print "Playing Video..."
end if

while true
' Nothing to do here! After the first synchronize is called, roSyncManager invisibly sends
' sync messages every sec, and the followers adjust playback to match. These messages don't
' seem to be of type roSyncManagerEvent and we can't detect them via BrightScript. They "just work".
end while



' FOLLOWER - Minimum example of Enhanced Sync
' Based on: https://brightsign.atlassian.net/wiki/spaces/DOC/pages/370673205/roSyncManager
' - (Assumes that each player already has manual IP and PTP domain set in registry)
' - Insert your filename below!

print "ENHANCED SYNC TEST - FOLLOWER"
' Create a sync manager with default address and port.
aa1=CreateObject("roAssociativeArray")
aa1.Domain = "BS1"
s=CreateObject("roSyncManager", aa1)
p=CreateObject("roMessagePort")
s.SetPort(p)

' Create a video player - we're going to play a seamlessly looped file
v=CreateObject("roVideoPlayer")
v.SetLoopMode(True)

While true
' Listen for explicit messages from leader script's roSyncManager.Synchronize
' Once playback begins, further messages are being sent every sec and the player
' will adjust to match, with no further script interaction.

msg=Wait(0, p)

if type(msg) = "roSyncManagerEvent" then
print "roSyncManagerEvent received..."
aa = CreateObject("roAssociativeArray")
aa.Filename = "Sync Test 1 (30sec HD fixed PCM).mov"
aa.SyncDomain = msg.GetDomain()
aa.SyncId = msg.GetId()
print "Payload = " + aa.SyncId 'The optional payload sent with the synchronize message
aa.SyncIsoTimestamp = msg.GetIsoTimestamp()
print "Timestamp = " + aa.SyncIsoTimestamp

ok = v.PlayFile(aa)

if ok then
print "roSyncManagerEvent updated video player"
end if
else
print "Other event received. Type:" + type(msg)
end if

End While

Disclaimer: This code is tested but I'm no expert! Hope it helps somebody.

3 comments

  • 0
    Avatar
    Bright Scripters

    Thanks for sharing!

    Isn't syncing with BrightAuthor an easier option?

  • 0
    Avatar
    Zach Poff

    Absolutely. BA makes this painless. But I often work with students and in gallery situations where a script method is much more maintainable: I can throw a leader or follower script on a card and tell them to add their video and go. This also makes last-minute video changes easy without me present. (AFAIK, BA obfuscates media in the pool folder, so if you want to update your video assets in the future, you need to go all the way back to the BA project.)

    I wrote this in my code comments, but just to reiterate: As of October 2021, the docs for roSyncManager seem a bit off. To differentiate between a leader and follower, I found that I needed to use roSyncManager.SetMasterMode(True) but the docs say roSyncManager.SetLeaderMode(True).

    This, and many other important details about Enhanced Synchronization can be gleaned from a careful reading of the scripts uploaded to the Play Random Syncronized Video thread by (BS employee?) "Romeo". It took me awhile to stumble across that goldmine so maybe this will help others!

     

  • 0
    Avatar
    Bright Scripters

    Good stuff!

    Empowering other people to make last minute changes is important too, so you can move on to something else :)

    Would love to connect with you

    https://www.linkedin.com/in/bright-scripters-7b685813b/

Please sign in to leave a comment.