Music Box won't run on battery power?

I do not think it is your code, it works when powered by the USB. I think you will find your problem is in the power supply. Something relative simple like the battery cannot supply the necessary power. Maybe the voltage is dropping to low or is wrong. You need a voltmeter of some type to check this out or go to higher capacity batteries. If you are using a 9V battery no need to go further that is the problem. Your pretty picture frizzy thing is not much help as it does not show the power and ground sources and connections. A schematic would be much better.