Cycling with headphones in

Is that allowed? Do people do that? Or is it generally considered unsafe?