recipe-521884.py 文件源码

python
阅读 37 收藏 0 点赞 0 评论 0

项目:code 作者: ActiveState 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号