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…
I have noticed as well that people with only one earphone in are still wanting to be talked to. It’s a technique that I’ve employed as well actually: when I don’t want to talk, I’ll have both in and when I do, I’ll only use the one. Hope this helps too, might be different for others though.