PennController for IBEX › Forums › Support › Penn Controller Audio Segment Playing › Reply To: Penn Controller Audio Segment Playing
April 26, 2023 at 4:00 am
#10477

Keymaster
Hi,
There is no built-in command in PennController for that, but it’s easily implementable using a Function element:
newTrial( newButton("Start").print().wait().remove() , newAudio("sample", "https://freetestdata.com/wp-content/uploads/2021/09/Free_Test_Data_100KB_MP3.mp3") , newFunction("playSegment", async ()=>{ const a = getAudio("sample")._element.audio; a.pause(); a.currentTime = 1.25; // start at 1.25s a.play(); await new Promise(r=>(function checkAudio() { if (a.currentTime >= 2.30) { // end at 2.30s a.pause(); r(); } else setTimeout(checkAudio); })()); }) , newButton("Play segment").callback( getFunction("playSegment").call() ).print() , newButton().wait() )
Jeremy