def main(args):
# look at command line
streaming = False
if args and args[0] == '-s':
streaming = True
args.pop(0)
if not args:
print >>sys.stderr, "usage: soundplay [-s] FILE"
print >>sys.stderr, " -s use streaming mode"
return 2
# initialize pygame.mixer module
# if these setting do not work with your audio system
# change the global constants accordingly
try:
pygame.mixer.init(FREQ, BITSIZE, CHANNELS, BUFFER)
except pygame.error, exc:
print >>sys.stderr, "Could not initialize sound system: %s" % exc
return 1
try:
for soundfile in args:
try:
# play it!
if streaming:
playmusic(soundfile)
else:
playsound(soundfile)
except pygame.error, exc:
print >>sys.stderr, "Could not play sound file: %s" % soundfile
print exc
continue
except KeyboardInterrupt:
# if user hits Ctrl-C, exit gracefully
pass
return 0
评论列表
文章目录