python通過win32com庫播放mp3文件

mxw8 9年前發布 | 1K 次閱讀 Python

# 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()</pre>

 本文由用戶 mxw8 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!