Some users have reported an issue in which iPhone headphone volume erratically jumps up or down while the iPod app, Pandora or other apps are in use. The problem occurs most frequently with third-party headphones (including those from Skullcandy, V-Moda and others) that include a microphone.
It appears that this problem occurs when the mic inadvertently receives audio input from ambient noise.
Block the mic. Blocking the microphone on third-party headphones, by adhering tape or via other means, (albeit kludgey) appears to resolve this issue.
Update to iOS 4.0.1. Some users have reported that this issue is eliminated or occurs less frequently after the update to iOS 4.0.1.