0

Multiplayers, loop and UDP commands

I'm new to Brightscript and need some help to fine-tune my code.

I've got 6 BS players wich all plays there own video file after a UDP command.

The code I'm using is as follows (master and client)
But i really like to shorten the code so i can call the play command using a subroutine or function, but did not got it to work.
The following code is working, but it is not very clean.

Hope you can help.

' Brightsign Multi-Screen Sync Script - MASTER
' --------------------------------------------

Sub Main()

 

SetupNetwork()


VideoFile$ = "w1.mpg"
VideoMode$ = "1920x1080x30p"
' video heeft formaat: 800x600x75p
audioVolume = 15 ' (the volume of the audio output, in percent... These players have LOUD outputs so try 10-20 for sane headphone levels!)

' ==CREATE OBJECTS==



snd = CreateObject("roDatagramSender")
receiver = CreateObject("roDatagramReceiver", 21076)
v = CreateObject("roVideoPlayer")
mp = CreateObject("roMessagePort")
mode=CreateObject("roVideoMode")

snd.SetDestination("255.255.255.255", 11167) ' send to all receivers

v.SetPort(mp)
receiver.SetPort(mp)
v.SetVolume(audioVolume)

mode.SetMode(VideoMode$)



while true

event = wait(0,mp)
if type(event) = "roDatagramEvent" then
UDPCommand = event.GetString()

if UCase(UDPCommand) = "START" then
v.PreloadFile(VideoFile$)
snd.Send("pre")
sleep(500)
snd.Send("ply")
mode.SetPowerSaveMode(false)
ok = v.Play()

else if UCase(UDPCommand) = "STOP" then
ok = v.Stop()
snd.Send("stop")
mode.SetPowerSaveMode(true)

else if UCase(Left(UDPCommand,2)) ="SV" then

audioVolume = strtoi(Right(UDPCommand,len(UDPCommand)-2))
v.SetVolume(audioVolume)

else if UCase(UDPCommand) = "MUTE" then
v.SetVolume(0)

else if UCase(UDPCommand) = "UNMUTE" then
v.SetVolume(audioVolume)
end if

else if type(event) = "roVideoEvent" then

if event.GetInt() = 8 then
v.PreloadFile(VideoFile$)
snd.Send("pre")
sleep(500)
snd.Send("ply")
mode.SetPowerSaveMode(false)
ok = v.Play()
end if

end if
end while

End Sub


Sub SetupNetwork()
nc = CreateObject("roNetworkConfiguration", 0)
nc.SetIP4Address("10.2.3.11")
nc.SetIP4Netmask("255.248.0.0")
nc.SetIP4Broadcast("10.7.255.255")
nc.SetIP4Gateway("10.2.1.10")
nc.Apply()
End Sub



===================================================================
' Brightsign Multi-Screen Sync Script - SLAVE 2
videoFile = "W2.mpg"
VideoMode$ = "1920x1080x30p"
audioVolume = 0


mode=CreateObject("roVideoMode")
mode.SetMode(VideoMode$)


nc = CreateObject("roNetworkConfiguration", 0)


nc.SetIP4Address("10.2.3.12")
nc.SetIP4Netmask("255.248.0.0")
nc.SetIP4Broadcast("10.7.255.255")
nc.SetIP4Gateway("10.2.1.10")

nc.Apply()

receiver = CreateObject("roDatagramReceiver", 11167)

v = CreateObject("roVideoPlayer")
v.SetVolume(audioVolume)
sleep(200)

v.PreloadFile(videoFile)

p = CreateObject("roMessagePort")

receiver.SetPort(p)


listen:
msg = wait(2000,p)

if type(msg) = "roDatagramEvent" then

udpCommand = msg.GetString()

if udpCommand = "pre" then
v.PreloadFile(videoFile)
elseif udpCommand = "ply" then
mode.SetPowerSaveMode(false)
v.Play()
elseif udpCommand= "stop"
v.Stop()
mode.SetPowerSaveMode(true)
endif

endif

goto listen

 

0 comments

Please sign in to leave a comment.