You have a lot of questions. (don't worry, that's definitely a good thing :) )
Both are ok. The two sentences mean the same thing here.
These two conjunctions ''while'' and ''when'' are very similar. Here, they both show simultaneous events.
''When'' can also be used for non-simultaneous events. For example:
''The fireworks had already finished when we arrived''. (non-simultaneous)
''When they saw us, they ran away''. (immediately after)