0

Posting Video Playback Position to Local Server

**Subject**: Assistance Required with Posting Video Playback Position to Local Server

Hello BrightSign Support,

I am using an LS424 player with a Web Folder deployment for my presentation. Everything is set up on a local network.

**Objective**:

I have a looping video presentation that works perfectly. However, for content synchronization across multiple devices in our building (Phones and Tablets), I need the video's current playback position. I aim to send this position to a local ASP.NET Core website with an endpoint prepared to receive the data.

**Attempted Solution**:

  1. I tried leveraging BrightAuthor: Connected, but couldn't find a way to achieve this.
  2. I decided to modify the `autorun.brs` file post-publishing to the web folder, ensuring file hash accuracy, and making necessary updates to `pool` and `current-sync.json`.
  3. Within the code, I saved the reference to the `roVideoPlayer` and made several custom modifications to the Event Loop and introduced a `PostPosition` subroutine.

**Problem**:

The presentation still loads and the video plays after my changes, but the local server isn't receiving the expected messages.

**Code Snippets for Reference**:

In main sub, store global references:

Library "autoplugins.brs"




Sub Main()




  autorunVersion$ = "10.0.98" 'Bacon in development

  customAutorunVersion$ = "10.0.0"




  ' create global registry section to be used throughout script

  globalAA = GetGlobalAA()

  globalAA.registrySection = CreateObject("roRegistrySection", "networking")




  ' -----------------------------------

  ' Custom Video Playback Support

  ' -----------------------------------

  globalAA.videoPlayer = invalid

  localServerURL = "https://OurLocalWebsite.com/api/videoposition"

  urlTransfer = CreateObject("roURLTransfer")

  urlTransfer.SetURL(localServerURL)

  globalAA.urlTransfer = urlTransfer

  ' -----------------------------------


Next, I found in the code where roVideoPlayer is created and save the reference like so:

  videoPlayer = CreateObject("roVideoPlayer")

  ' -----------------------------------

  ' Custom Video Playback Support

  ' -----------------------------------

  globalAA.videoPlayer = videoPlayer

  ' -----------------------------------


Then in the EventLoop, I added the following:

Sub EventLoop()




  SQLITE_COMPLETE = 100

  previousPositionInMillis = -1




  ' -----------------------------------

  ' Custom Video Playback Support

  ' -----------------------------------

  globalAA = GetGlobalAA()

  videoPlayer = globalAA.videoPlayer

  urlTransfer = globalAA.urlTransfer

  ' -----------------------------------




  while true

    if videoPlayer = invalid then

      videoPlayer = globalAA.videoPlayer

    end if




    msg = wait(0, m.msgPort)




    m.diagnostics.PrintTimestamp()

    m.diagnostics.PrintDebug("msg received - type=" + type(msg))




    if type(msg) = "roControlDown" and stri(msg.GetSourceIdentity()) = stri(m.svcPort.GetIdentity()) then

      if msg.GetInt() = 12 then

        stop

      end if

    end if

   

    eventHandled = false




    ' -----------------------------------

    ' Custom Video Playback Support

    ' -----------------------------------

    if videoPlayer <> invalid then

        positionInMillis = videoPlayer.GetPlaybackPosition()

        if positionInMillis - previousPositionInMillis > 1000 then

            m.diagnostics.PrintDebug("Post Position: " + positionInMillis.ToStr())

            previousPositionInMillis = positionInMillis

            positionInSeconds = positionInMillis / 1000

            PostPosition(urlTransfer, positionInSeconds)

        end if

    end if      

    ' -----------------------------------


Here is my post code:

' -----------------------------------

' Custom Video Playback Support

' -----------------------------------

' The following is called from the Event Loop

Sub PostPosition(urlTransfer, position As Integer)

    postData = CreateObject("roAssociativeArray")

    postData.AddReplace("id", 3)  ' Special Exhibit ID

    postData.AddReplace("position", position)

    response = urlTransfer.AsyncPostFromString(postData.ToJsonString())

end sub

' -----------------------------------





 

 

**Request**:

Having invested significant effort, I believe I am close to a solution. Could you please review the steps and code snippets provided to identify any potential errors or missing elements?

 

Your assistance is much appreciated.

 

Warm Regards,

Bobby Ortiz

7 comments

  • 0
    Avatar
    Monica Knutson

    Seems like quite a lot of customization.  

    May I ask why you wouldn't send it as a UDP data packet to your webserver?

    How often do you need to sync your content over phones and tablets?  Upon the video start?   Upon the video end?  You can set a video timecode event  using BrightAuthor as well that could send a data packet.  However you choose to do it there will be some network lag.

  • 0
    Avatar
    Bobby Ortiz

    I am afraid I do not know how to do that either. Can I send a UDP packet every second as a video loop plays? My end point is expecting something like {"id":3,"position": 10}

  • 0
    Avatar
    Monica Knutson

    There is a heartbeat script on the BrightSign GitHub that may be able to be tweaked to do what you wanted to do.  I use it to send a query string to a PHP page on a website every 600 seconds.  You can call a plugin script as often as you need it to.  You may need to set a variable to pass along the position and ID to the script.

    You may want to reach out to @BrightScripters to help you out with this as well.  You can see their info here on this similar post:

    https://support.brightsign.biz/hc/en-us/community/posts/8091601352219-sending-timecode-via-UDP

  • 0
    Avatar
    Bobby Ortiz

    The example you linked to is for BrightAuthor, and all of our presentations until now have been created using "BrightAuthor: Connected". The feature sets are not the same. I would have to change our process and learn BrightAuthor. Might be worth it, but I started using BA Connected because I thought that was the new and recommended way of doing presentations. Especially since we use the BSN Control Cloud for deployments. 

    The only way I have found to get the playback position of the video is to get a reference to the player and calling 

    positionInMillis = videoPlayer.GetPlaybackPosition()

    If I knew how to get a reference to the player being used, get how to get the above value, then I think I could use your suggestion. I would not need to modify the autorun.brs directly myself.

  • 0
    Avatar
    Bobby Ortiz

    I believe I am very close to having my code working.

    I get this error:
    Script runtime error: Member function not found in BrightScript Component or interface. (runtime error &hf4)
     
    for this line: response = urlTransfer.PostFromString(postData.ToJsonString())
     
    I have also tried the following method with the same result:
    AsyncPostFromString
     
    Here how I initialize the urlTransfer:
          localServerURL = "https://MyWebSite/api/videoposition"
          urlTransfer = CreateObject("roURLTransfer")
          urlTransfer.SetURL(localServerURL)
     
     
  • 0
    Avatar
    Bright Scripters

    If you provide a link to your code we could take a look and help.

  • 0
    Avatar
    Bobby Ortiz

    I was able to modify the autorun.brs file and add a timer. I think react to timer events in the eventloop. So, I would have preferred a way to do all this within BrightAuthor, but this works well.

Please sign in to leave a comment.