Strange Behavior Threaded TSound

BlitzMax Forums/BlitzMax Programming/Strange Behavior Threaded TSound

Firstdeathmaker(Posted 2009) [#1]
Hi there,

ive got a strange behavior of my program:

When I uncomment the rem-block in the beginning, I hear the sound in the uncommented section and also in the end.

When I run it like I post it here, I hear no sound at all, although it should play the sound in the section above where I get the sound out of the TMap. Another guy tried the code on his system, but it worked well on Windows Vista. On Win XP we both get this strange behavior.



SuperStrict

Local s:TSound
Local c:TChannel
Local map:TMap = CreateMap()

Rem
s = LoadSound("data/s1.ogg")
c = PlaySound(s)
Delay 1000
c.stop()
End Rem


Local sfxList:TList = New TList
sfxList.AddLast("data/s1.ogg")
sfxList.AddLast("data/s2.ogg")
sfxList.AddLast("data/s3.ogg")

Local loader:TDataLoader = New TDataLoader
loader.setLoadFunction(LoadSound,0)
loader.setTargetMap(map)
loader.setUrlList(sfxList)
loader.start()

Graphics 400,300
Local cc:Int
While Not loader.isFinished()
   cc:+1
   Cls
   DrawText "Loading: " + Int(loader.getProgress()*100)+"%", (Sin(cc)+1)*GraphicsWidth()/4,10
   Flip
Wend


s:TSound = TSound(MapValueForKey(map,"data/s2.ogg"))
c:TChannel = s.Play()
Print "Sound exists: "+(s<>Null)
Print "Channel exists: "+(c<>Null)
Print "Channel plays: "+c.playing()

Repeat
   Cls
      DrawText("Music should be playing",10,10)
   Flip
Until KeyHit(KEY_ESCAPE)
End


'############## TDataLoader ################
Type TDataLoader
   Field loadFunction:Object(url:Object, flags:Int)
   Field flags:Int
   Field urlList:TList
   Field thread:TThread
   Field targetMap:TMap
   
   Field total:Int
   Field Current:Int
   
   Method setLoadFunction(f:Object(url:Object, flags:Int), flags:Int = 0)
      Self.loadFunction = f
      Self.flags = flags
   End Method
   
   Method setUrlList(urls:TList)
      Self.urlList = urls
   End Method
   
   Method setTargetMap(m:TMap = Null)
      targetMap = m
      If targetMap = Null targetMap = CreateMap()
   End Method
   
   Method start()
      Self.thread = CreateThread(TDataLoader.LoadThread, Self)
   End Method
   
   Function LoadThread:Object(data:Object)
      Local dl:TDataLoader = TDataLoader(data)
      If dl = Null
         Return Null
      EndIf
         
      dl.total = dl.urlList.Count()
      
      For Local url:Object = EachIn dl.urlList
         Local obj:Object = dl.loadFunction(url, dl.flags)
         If obj = Null Print "error occured when loading data"
         MapInsert(dl.targetMap, url, obj)
         dl.Current:+1
      Next
      Return dl
   End Function
   
   Method getProgress:Float()
      If total = 0 Return 1
      Return Float(Current) / total
   End Method
   
   Method getMap:TMap()
      Return Self.targetMap
   End Method
   
   Method isFinished:Byte()
      If ThreadRunning(Self.thread) = False
         DetachThread(Self.thread)
         Return True
      EndIf
      Return False
   End Method
End Type