Electromagnetic control of oscillating flows in a cavity