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中设置超时跳过,超时退出的方式

在工作中遇到过 个问题 执行一条代码时间过长 而且还不报错,卡死在那。还要继续执行下面代码,如何操作。 下面是个简单的实例 pip安装 第三方eventlet这个包 – pip inst...

django 实现编写控制登录和访问权限控制的中间件方法

django中,很多时候我们都需要有一个地方来进行更加详细的权限控制,例如说哪些用户可以访问哪些页面,检查登录状态等,这里的话就涉及到了中间件的编写了。 在django项目下的setti...

解决python 文本过滤和清理问题

问题 某些无聊的脚本小子在Web页面表单中填入了“pýtĥöñ”这样的文本,我们想以某种方式将其清理掉。 解决方案 文本过滤和清理所涵盖的...

python中abs&map&reduce简介

abs函数 可以把函数本身赋值给变量 >>> f = abs 变量可以指向函数 >>> f = abs >>> f(-10) 10...

对Pytorch中nn.ModuleList 和 nn.Sequential详解

简而言之就是,nn.Sequential类似于Keras中的贯序模型,它是Module的子类,在构建数个网络层之后会自动调用forward()方法,从而有网络模型生成。而nn.Modul...