How to get StreamSubscription from StreamBuilder - dart

When adding a listener to a RxDart PublishSubject I get a StreamSubscription. I can then use the StreamSubscription to pause and resume, is there any way to do that with a StreamBuilder?

No.
You cannot pause listening to a Stream using StreamBuilder. If you want to, you will have to manually subscribe to your Stream and call pause yourself.

Related

How to disable Trickle Timer in Contiki-NG?

I have one question for you. I want to disable the trickle timer in the rpl-mrhof.c file. I defined one flag name as Trickle_flag. I want to disable the Trickle timer in my program when the Trickle_flag is equal to 1 and the DIO transmissions will be suppressed. When the Trickle_flag is equal to 0 the DIO transmissions will be continued. I want to stop all node's DIO transmissions. Any idea how to change the trickle function?
The correct way how to disable a trickle timer is to call the trickle_timer_stop(tt) macro, where tt is the timer to stop. See the documentation of this macro.
Stopping DIO transmissions is a different question though. The Contiki RPL implementation was developed before the Trickle timer library existed, so it does not use the Trickle timer API, but instead implements the Trickle timers internally, through callback timers (struct ctimer). Don't use ctimer_stop(&instance->dio_timer) for this either, it will not give reliable results, as the rpl_reset_dio_timer function may be called by some events, which will restart the timer. Your best approach is filter out the DIO messages before they are sent, instead of messing with the Trickle timers in a way that's not expected by the developers of the code. You can add an if statement to dio_output based on the flag value, for example, to return immediately if the DIO suppression flag is set.

AVAudioSequencer - How to be notified when playback ends

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.

How to not invalidate observer when binding is disposed in RxSwift?

I'm quite new in RxSwift world and apparently I'm not using it correctly... I have a button that I would like to connect to an observer like this
button.rx.tap.bind(to: viewModel.someObserver).disposed(by: disposeBag)
where someObserver in viewModel is initialized as follows:
let publishSubject = PublishSubject<Void>()
someObserver = publishSubject.asObserver()
someObservable = publishSubject.asObservable()
However, when Disposable created with binding is disposed, PublishSubject which is used both as Observer and Observable gets invalidated and all new subscriptions are immediately disposed.
I would like to use my PublishSubject for a longer time and be able to subscribe to it after the binding is disposed. How to achieve that?
Have a look at PublishRelay, which can't terminate with an error or completed event.
Binding the taps to a PublishRelay will simply ignore the completed event (source) once the subscription is disposed, e.g. when the button is deallocated. This will allow you to subscribe to the PublishRelay at a later point

How to check if sound played in delphi?

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.

Access an AVAudioPlayer on its current thread

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.

Resources