python musicplayer

一个python写的音乐播放器,因为不熟悉gui所以只能先写个简单的。用到了pygame,os 等库

#!/usr/bin/env python

#coding=utf-8

import os,pygame

path_file=os.listdir('./')

#print os.path.splitext(path_file[0])

musicList=[]


def play():

    for music in musicList:

        pygame.mixer.music.load(music)

        pygame.mixer.music.play()

        print music

        while pygame.mixer.music.get_busy():

            pass

for files in path_file:

    if os.path.splitext(files)[1]=='.mp3':

        musicList.append(files)

flag = raw_input('请输入播放模式: (1)顺序播放(o)哦 (2)列表循环(l)')

if flag == 'o':

    play()

elif flag=='l':

    while True:

        play()

else:

    print 'Error :  请输入正确选项'

你可能感兴趣的:(python musicplayer)