Note my changes above. Note that "ok" is always wrong. It's either "OK" (regardless of where it comes in the sentence), "Okay" (only at the start of a sentence) or "okay" (anywhere else in a sentence. Don't forget to end a question with a question mark.
It's fine. I'm sure someone will suggest that it means he likes doing both things at the same time. However, I encourage people to use logic and common sense. If that were the meaning, B would say "He likes to swim while listening to music" or "He likes to listen to music while swimming".