The problem was due to the MediaRecorder element not automatically stopping when the trial ends prematurely, causing the MediaRecorder element from the next trial to crash. The solution consisted in calling stop on the MediaRecorder element before calling end in the callback
Jeremy