Reply To: run command while MediaRecorder is recording

PennController for IBEX Forums Support run command while MediaRecorder is recording Reply To: run command while MediaRecorder is recording

#10685
Jeremy
Keymaster

Hi,

The most straightforward solution that will give you the most control is probably to code the recording interface yourself. Here’s an example:

newTrial(
    // create the elements but don't print/start them yet
    newButton("Done"),
    newMediaRecorder("audio").log()
    ,
    newButton("Stop recording")
        .callback(
            // Whenever stop is clicked we remove it, stop+print the recorder, and (re-)print record and done
            getButton("Stop recording").remove(),
            getMediaRecorder("audio").stop().print(),
            getButton("Record").print(),
            getButton("Done").print()
        )
    ,
    newButton("Record")
        .callback(
            // Whenever record is clicked we remove it, remove done, remove+start the recorder and print stop
            getButton("Record").remove(),
            getButton("Done").remove(),
            getMediaRecorder("audio").remove().record(),
            getButton("Stop recording").print()
        )
        .print() // start the trial by printing record
    ,
    // the script will stay on this line until done is clicked
    getButton("Done").wait()
)

Since you handle recording manually, you’ll want to hide the default “Record” button printed along with the MediaRecorder element. Just add this to Aesthetics/PennController.css:

.MediaRecorder-record {
    display: none;
}

Jeremy