Just for the purpose of listening, when I was without my music for 10 days, I listened to my favorite 24-minute song in my head. I do this with other things, as long as I've listened to them enough. It's fun! I get caught up in this so much that I'm "listening" to the same song in my head over and over, forgetting to listen to the actual song on my computer/cdplayer. lol I could probably listen to Dark Side of the Moon in its entirety, in my head, granted my attention doesn't slip away lol.
But it's weird! The music will be going, then if I want to "rewind" to hear a certain part again, it's like the track's still going and I can't! xD
As for composing? I've done some mild songwriting and writing melodies here and there. I can play something then "know" what I want to put next. When I'm listening to song for one of the first times, this will come to me automatically: I'll hear the musicians playing, then in my mind: "If I had written this song, the next thing I would do is..." and naturally when the song moves on, I'm either happy that they did what I would've, or disappointed that they chose something else I would not have.
In my own songwriting, it's creativity. I can "make" or "hear" a melody in my head. It'll be pretty good, too. It can come whenever. The problem is remembering it, since I'm not always home. When I get home, sometimes I'll forget what it was. Usually I can "sing" it (changing the octaves around so that my voice can project the notes) and record it on my phone. Which I've started to do, but doesn't always end up right... I have a backing band in my when I'm "hearing" it, so when I hear what I recorded... just the single melody, I'm thinking... "Wait, this doesn't sound right." The rhythm I was thinking then, doesn't match to what I hear now. It's so hard I can't keep the melody with me for a longer time!
When it comes to writing, really, the whole process is unpredictable, and sometimes, unfortunately, impossible.