I'm using SndPlaySound(pchar('wav.wav'), snd_ASync); function and it is works but I want to know when selected wav is still playing or already played. How to get a return value?
SND_ASYNC does not provide the information you are looking for. Use SND_SYNC instead. To avoid blocking your main thread, call sndPlaySound() in a worker thread.
Alternatively, have a look at Delphi's TMediaPlayer component. It can run asynchronously (set its Wait property to false), and you can use its OnNotify event (set its Notify property to true) to be told when its Play() method finishes playback.
Related
I am using AVAudioSequencer with AVAudioEngine and I am having just one single problem: how do I get the sequencer to notify when a track or file has reached its end?
I know there is an AVAudioPlayerNodeCompletionHandler thing, but then, AVAudioSequencer is not derived from AVAudioPlayerNode.
So far, the only thing I could think of was periodically comparing the currentPositionInBeats property in AVAudioSequencer with the lengthInBeats property in AVMusicTrack (the isPlaying property in AVAudioSequencer just doesn't go false when the sequencer goes beyond this limit,) but I don't like polling.
Any help is appreciated.
Take a look at this WWDC 2018 video:
https://developer.apple.com/videos/play/wwdc2018/714/?time=1897
At about 31:30, we see a slide and hear a narration that says we can call a URLSession's task's resume on a background queue, and that the quality of service ("QoS") of this queue will be used to prioritize the request.
Cool! I didn't know that. So I can say something like this:
DispatchQueue.global(qos: .background).async {
task.resume()
}
However, the next sentence says that "all the messages that it sends to your delegates will respect this QoS."
Really? In what sense? I have tried to examine the threading of the delegate callbacks, and they are not being automatically called back on the same global queue. And I don't know how else to characterize or detect the QoS of the current queue/thread. Moreover, if you supply a delegate, you must specify a callback queue in any case. So what does that sentence mean, exactly?
I'm using a series of AVAudioPlayers concurrent with the main thread using dispatch_async. Before playing each one I must query, whether it is playing using its isPlaying method.
I am generally unfamiliar with multithreading, so how would I go about calling the isPlaying method on the thread that the AVAudioPlayer is currently working on?
You can access the property playing directly on main thread because the operation is read, so it is safe I think :)
But you can't use it to judge if playback has completed as document says : Important: Do not poll this property to determine when playback has completed, instead implement the specified delegate method
You should use delegate and implement the method - (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag, if the method is called, it means the player stop.
After calling ReadDirectoryChangesW (in overlapped mode) it returns 1 (true) in two opposite situations: 1) no files changes, 2) one or more file changed; But in first situation no data passed to IOCP and in second situation passed pointer to my overlapped struct.
How to determine if it passed my overlapped struct or not to IOCP while calling ReadDirectoryChangesW ? In another words how to determine does ReadDirectoryChangesW found changes or not?
In some part of my code I call GetQueuedCompletionStatus and get full information about changed files, but before it I wanna to know only fact: was changes or not;
If you're using ReadDirectoryChangesW() with an IOCP then you're using it in asynchronous mode and so after calling it you should wait for it to report the next change as it occurs.
Once you get a completion notification from the IOCP you can process it and then call ReadDirectoryChangesW() again to get more notifications.
I am making a turnbased game for iOS with game center, 2 participants per match. I would like to implement a time limit on every turn, so that a player don't have to wait forever for the other player to finish its turn. I have tried:
currentMatch endTurnWithNextParticipants:[[NSArray alloc] initWithObjects:nextParticipant,nil] turnTimeout:GKTurnTimeoutDefault matchData:data completionHandler:^(NSError *error)
but nothing happens, the player still has forever to do their turn, so I am obviously missing something here.
What happens when the time limit is reached? How does gamecenter handle this, and where should I handle this?
That method updates the data stored on Game Center for the current match.
According to Apple Docs:
If the next player to act does not take their turn in the specified interval, the next player in the array receives a notification to act. This process continues until a player takes a turn or the last player in the list is notified.
When this method is called, it creates a new background task to handle the request. The method then returns control to your game. Later, when the task is complete, Game Kit calls your completion handler. Keep in mind that the completion handler may be called on a thread other than the one originally used to invoke the method. This means that the code in your block needs to be thread-safe.
I think you need to also end the players go on their end programatically.