Player object and memory

Peter T. Evensen pevensen at siboneylg.com
Thu Mar 9 12:32:23 EST 2006


I am trying to play a sequence of MP3s.  I am using 3 interleaved players 
to speed up the transition between the sounds.  I set up the first 3 sounds 
on Player 1 - Player 3.  I then start Player 1 and when I get a playStopped 
message, I start Player 2 and set the filename for Player 1 to the next 
sound file for that player (if there is one).  Is there any memory 
management issues I need to be aware of?  My stack freezes eventually on 
XP, both as a standalone, and in the IDE.

I am doing this under Rev 2.6.1, but it also happens on 2.7.  In watching 
the messages, it freezes right after a startPlaying mesage is sent (but no 
sound plays, and I get a watch cursor and have to force quit Rev).  It 
doesn't freeze right away, but only after I have played a (seeming 
variable) number sound sequences.

Is this a bug?  Do I need to manually free any resources?  I haven't tested 
it most on Mac OS X, but I haven't seen it freeze on there.

In putting in copious puts to a field, before it freezes, there is a long 
pause when I set the next filename in QueueNext.  This happens after I 
start the next player whose sound does NOT play.

I have a group setup to contain the players.  I originally had the code 
attached to each player and had the same result.  I have generalized my 
code and moved it to the group script.  My group script is the following 
(perhaps someone can see a problem):

function NextPlayerNumber pName
   put word 2 of pName into tPlayerNumber
   put tPlayerNumber + 1 into tPlayerNumber
   if tPlayerNumber > the number of players of me then put 1 into tPlayerNumber
   return tPlayerNumber
end NextPlayerNumber

on playStopped
   put NextPlayerNumber(the short name of the target) into tNextPlayer
   if the cpDone of player ("Player" && tNextPlayer) of me is not true then
     start player ("Player" && tNextPlayer) of me
     QueueNext
   else
     StoppedReading
   end if
end playStopped

on QueueNext
   put the cpSoundList of the target into tCurrentSoundList
   if tCurrentSoundList is not empty then
     if there is no file the first item of tCurrentSoundList then
       ReportError "Cannot find file:" && the first item of 
tCurrentSoundList, "Missing Sound File"
       set the cpDone of the target to true
     else
       lock messages
       set the filename of the target to the first item of tCurrentSoundList
       unlock messages
       delete item 1 of tCurrentSoundList
       set the cpSoundList of the target to tCurrentSoundList
     end if
   else
     set the cpDone of the target to true
   end if
end QueueNext

on SetSoundFiles pSoundFileList
   put the number of players in me into tNumPlayers

   -- split up the list among the players, interleaving the sounds
   repeat with i = 1 to the number of items in pSoundFileList
     put (i - 1) mod tNumPlayers + 1 into tPlayerNumber
     put tPlayerList[tPlayerNumber] & item i of pSoundFileList & "," into 
tPlayerList[tPlayerNumber]
   end repeat

   -- queue up the first sound file for each
   lock messages
   repeat with i = 1 to tNumPlayers
     if there is no file the first item of tPlayerList[i] then
       ReportError "Cannot find file:" && the first item of tPlayerList[i], 
"Missing Sound File"
       set the cpDone of player ("Player" && i) to true
     else
       set the filename of player ("Player" && i) to the first item of 
tPlayerList[i]
       delete the first item of tPlayerList[i]
       set the cpSoundList of player ("Player" && i) to tPlayerList[i]
       set the cpDone of player ("Player" && i) to false
     end if
   end repeat
   unlock messages
end SetSoundFiles

on StartPlaying
   start player "Player 1" of me
end StartPlaying



Peter T. Evensen
http://www.PetersRoadToHealth.com
314-629-5248 or 888-628-4588  




More information about the use-livecode mailing list