Both. At very loud volumes even short bursts can cause permanent damage, and prolonged exposure to loud volumes also does. If you get any decent headphones and play at the level of a real piano, it probably wouldn't damage your ears more than a real piano would. The only critical factor in this matter is the intensity of the sound, so you should be careful not to over exceed certain levels... if you have even the slightest feeling of 'pain' or discomfort, even if it is only for a split second, use an equalizer to scale down the frequencies which are causing the discomfort.