I do a ton of bike riding, for Triathlon Competitive Training. Headphones (earbuds) are dangerous, and actually illegal to use in competition, but you may get away with a small music device mounted on the bars. I think the rule reads "all accessories must be able to pass through an 8" loop". Something like that. It's an obscure rule.
Triathlon Officials would probably Disqualify for such an attachment anyway, simply because it would be considered endangerment to have a music box of any kind on a bike in competition. But for TRAINING? I'd use it all the time, provided it is water resistant. I ride in the rain, or, sometimes I'm riding and it rains because I ride for long periods of time. Sure would be nice to have some music.