Can I listen to music during running on a treadmill in my earphones?
Yes, but only if this is necessary or enhancing of the exercise.
We find a number of leniencies concerning playing music when this is done for purposes other than enjoyment.
For instance, it is permitted for somebody whose livelihood depends on playing musical instruments to play music (to practice, or for non-Jews). As Rav Moshe Feinstein writes (Iggros Moshe, Orach Chaim Vol. 3, no. 87), it is permitted to study music, or to teach music, when one does so for reasons related to one’s livelihood, and not for pleasure (see also Seder Pesach Kehilchaso, Chap. 12, no. 16; Tzitz Eliezer Vol. 16, no. 19).
It is likewise permitted to play music for the purpose of calming a young child (who has not reached the age of chinuch), or for calming and soothing the sick (Shut Devar Shalom, Vol. 4, no. 80; Nitei Gavriel, Pesach Vol. 3, Chap. 53, no. 5, 7). It is likewise permitted to listen to music while driving, if the purpose of the music is to keep the driver alert to his environment (one should preferably play slow (classical or other) music, and not dance music).
Therefore, when the music is not being played for enjoyment, but only for “keeping the beat” or keeping to one’s running steps, there is no prohibition. However, one should ensure that the intention is not to enjoy the music, but to keep the rhythm, and one should not select one’s favorite pieces for the occasion.