def dev_stop_then_play(): log("thread stops the playback") AATApp.playback_stop(device) time.sleep(4) log("thread starts the playback") AATApp.playback_nonoffload(device) log("thread returns")
def playback_task_run(device): log("dev_playback_start(nonoffload)") AATApp.playback_nonoffload(device) th = DetectionStateChangeListenerThread() th.start() log("ToneDetector.start_listen(target_freq={})".format(OUT_FREQ)) ToneDetector.start_listen( target_freq=OUT_FREQ, cb=lambda event: th.tone_detected_event_cb(event)) # Waiting for the event of tone detected, blocking with a 5 secs timeout if th.wait_for_event(DetectionStateChangeListenerThread.Event.ACTIVE, timeout=5) < 0: log("the tone was not detected, abort the function...") AATApp.playback_stop(device) return time.sleep(1) # The thread just stops the playback and then continues def dev_stop_then_play(): log("thread stops the playback") AATApp.playback_stop(device) time.sleep(4) log("thread starts the playback") AATApp.playback_nonoffload(device) log("thread returns") threading.Thread(target=dev_stop_then_play).start() log("Waiting for {} Hz pure tone detected".format(OUT_FREQ)) # Waiting the event that the tone is detected again after the tone is missing elapsed = th.wait_for_event( DetectionStateChangeListenerThread.Event.RISING_EDGE, timeout=10) log("elapsed: {} ms".format(elapsed)) log("ToneDetector.stop_listen()") ToneDetector.stop_listen() th.join() log("dev_playback_stop(nonoffload)") AATApp.playback_stop(device)