I noticed that cocoamessage is used in the play(dummy) thread.
In a thread, you have to create a cocoa pool yourself so that it does not conflict with the pool from the MainScope (internal PB). The internal Cocoa Pool is cleaned up when WaitWindowEvent is called. Otherwise this leads to the described error in WaitWindowEvent.
You should also NOT use KillThread, but a variable that tells the thread that it should be terminated.
KillThread only leads to memory leaks ...
Update code Play
Code: Select all
Procedure play(dummy)
Shared AVAudioPlayer
Shared nowPlaying
Protected NSPool.i
Protected currentTime.d
NSPool = CocoaMessage(0, 0, "NSAutoreleasePool new")
debugLog("playback",nowPlaying\path)
AVAudioPlayer = CocoaMessage(0,CocoaMessage(0,0,"AVAudioPlayer alloc"),
"initWithContentsOfURL:",CocoaMessage(0,0,"NSURL fileURLWithPath:$",@nowPlaying\path),
"error:",#Null)
If AVAudioPlayer
If CocoaMessage(0,AVAudioPlayer,"play") = #YES
PostEvent(#evPlayStart)
While CocoaMessage(0,AVAudioPlayer,"isPlaying") Or nowPlaying\isPaused
Delay(10)
Wend
EndIf
CocoaMessage(0,AVAudioPlayer,"dealloc")
AVAudioPlayer = 0
EndIf
PostEvent(#evPlayFinish)
CocoaMessage(0, NSPool, "release")
EndProcedure