The quality factor of a superconducting rf resonator in a magnetic field