美文网首页
python musicplayer

python musicplayer

作者: 摘月亮的人 | 来源:发表于2017-12-01 10:09 被阅读0次

一个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

      本文链接:https://www.haomeiwen.com/subject/erzjbxtx.html