Yingzhou210, both sentences are correct. To use one or the other is a matter of individual preference. However, if you want to be very particular about it, you'll have to write, "He walked along the street while listening to music."
Here's another similar example "The hawker walked the street selling his ware."