content: sub Main()
      screen = CreateObject("roSGScreen")
      port = CreateObject("roMessagePort") ' Changed m.port to local var port
      screen.setMessagePort(port)
  
      scene = screen.CreateScene("Scene")
      scene.setFocus(true) ' Ensure the main scene has focus initially
      screen.show()
  
      while(true)
          msg = wait(0, port)
          msgType = type(msg)
  
          if msgType = "roSGScreenEvent"
              if msg.isScreenClosed()
                  print "Screen closed, exiting app."
                  return
              end if
          else if msgType = "roSGNodeEvent" ' Events from nodes like VideoScene
              eventSource = msg.getNode()
              if scene <> invalid AND scene.isSubtype("Scene") AND scene.isSubtype("Component") AND scene.getFunctionName("handleVideoPlayerEvents") <> invalid
                  ' Check if the event is from a VideoScene or a node we care about
                  ' This check is a bit broad; ideally, we'd check if msg.getNode() is m.currentPlayer
                  ' or if msg.getField() is one of "state", "visible" from the video player.
                  ' The handleVideoPlayerEvents in Scene.brs already checks for m.currentPlayer.
                  scene.callFunc("handleVideoPlayerEvents", msg)
              end if
          end if
      end while
  end sub
  