For the sake of making something simple I decide to break some code up into its own function. Well, not getting the desired results. I have a channel that enters a loop, Function ChannelLoop as shown here with some lead in code removed that is not essential. The id value is set by the remote control. If the user select "OK", the procedure follow thru and enters the Function PlayLoop. I am passing the value of Id and msg to the PlayLoop as it is used in the function. When the Playloop is called, the id and msg is passed. The loop is entered, Step 1 passes, Step 2 passes. Instead of executing the line after Step 2, the code jumps to Step 6 and coninues printing Step 1, Step 2, Step 6 over and over. Oddly the stream loads and plays but the player is not shown on the screen because the value of m.status is never evaluated in the step after Step 2. What is suppose to happen is as the stream loads, if the msg.isStatusMessage() and msg.GetMessage() = "startup progress", the value of m.status is set, and the function m.paint is called. In this function m.status value decides on how the screen should look. Now, before breaking the code into functions, I had only one function, ChannelLoop. The code in PlayLoop was in the ChannelLoop function directly following m.player.Play(). Everything worked fine. Why did I break it out, thought it would be easier for future revisions. Can somebody take look and see if something is causing the code following Step 2 not to execute. Thanks a million.
while true
msg = wait(0, m.port)
if msg <> invalid
if (msg.isRemoteKeyPressed())
id = msg.GetIndex()]
if id=6
?"ENTER PLAY LOOP"
cname=m.cname[index]
cstream=m.cstream[index]
HLSURL=cstream
m.player.SetContentList([{
Stream: { url: HLSURL }
StreamFormat: "hls"
SwitchingStrategy: "full-adaptation"
}])
m.player.Play()
m.status=PlayLoop(id,msg)
end if
end if
end if
end while
The Playloop function shown below.
Function PlayLoop(id,msg) As Object
while id <> 0
'msg = wait(0, m.port)
?"STEP 1"
if msg <> invalid
?"STEP 2"
if msg.isStatusMessage() and msg.GetMessage() = "startup progress"
?"STEP 3"
m.paused = false
progress% = msg.GetIndex() / 10
if m.progress <> progress%
?"STEP 4"
m.status=2
m.progress = progress%
m.paint()
end if
'Playback progress (in seconds):
else if msg.isPlaybackPosition()
?"STEP 5"
if id= 2 or id=3
m.setup = SetupFramedCanvas
?"SETUP MADE. . ."
m.paint = PaintFramedCanvas
?"PAINT MADE. . ."
rect = m.layout.right
?"RECT MADE. . ."
m.status=3
exit while
else
m.status=2
m.position = msg.GetIndex()
m.paint()
end if
else if msg.isRemoteKeyPressed()
?"STEP 6"
id=msg.GetIndex()
print "Remote button pressed: " + id.tostr()
End if
End if
end while