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

yipeiwu_com5年前Python基础

本文实例讲述了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程序设计有所帮助。

相关文章

浅谈Python的list中的选取范围

序列是Python中最基本的数据结构。序列中的每个元素都分配一个数字 - 它的位置,或索引,第一个索引是0,第二个索引是1,依此类推。 Python有6个序列的内置类型,但最常见的是列表...

Python装饰器原理与用法分析

Python装饰器原理与用法分析

本文实例讲述了Python装饰器原理与用法。分享给大家供大家参考,具体如下: 1、装饰器的本质是函数,主要用来装饰其他函数,也就是为其他函数添加附加功能 2、装饰器的原则: (1) 装饰...

python 数据加密代码

1、hashlib import hashlib #创建一个哈希对象 md = hashlib.md5() #md = hashlib.sha1() #md = hashlib.sha2...

Python使用pymysql小技巧

在使用pymysql的时候,通过fetchall()或fetchone()可以获得查询结果,但这个返回数据是不包含字段信息的(不如php方便)。查阅pymysql源代码后,其实获取查询结...

Python中static相关知识小结

非 static 编译 不指定额外参数直接编译 Python: $ ./configure $ make 查看所依赖的共享库: $ ldd python linux-vd...