python使用win32com库播放mp3文件的方法

本文实例讲述了python使用win32com库播放mp3文件的方法。分享给大家供大家参考。具体实现方法如下:

# python supports com, if you have the win32 extensions
# check your python folder eg. d:\python23\lib\site-packages\win32com
# also http://starship.python.net/crew/mhammond/win32/downloads.html
# this program will play mp3, wma, mid, wav files via the windowsmediaplayer
from win32com.client import dispatch
mp = dispatch(“wmplayer.ocx”)
# use an mp3 file you have …
#tune = mp.newmedia(“c:/program files/common files/hp/memories disc/2.0/audio/swing.mp3”)
# or copy one to the working folder …
#tune = mp.newmedia(“bier1.mp3”)
# you can also play wma files, this cool sound came with xp …
tune = mp.newmedia(“c:/windows/system32/oobe/images/title.wma”)
mp.currentplaylist.appenditem(tune)
mp.controls.play()
# to stop playing use
raw_input(“press enter to stop playing”)
mp.controls.stop()

希望本文所述对大家的python程序设计有所帮助。

Posted in 未分类

发表评论