When people are in public places like a library, street, coffee shop,or subway, they often wear headphones as a way to create some private space.
People who wear headphones or earbuds in public usually do not want to be approached by strangers. If you know them well, it might be ok to ask, but it’s probably better to err on the side of leaving them alone.
The flip side: if you wear headphones, most people will assume that you don’t want to be approached. If you’re wearing headphones for sensory reasons but you want to interact with people, you will likely have to initiate it yourself. It also might help to let your friends know that you welcome interaction even when you are wearing headphones.