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

yipeiwu_com6年前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程序设计有所帮助。

相关文章

unittest+coverage单元测试代码覆盖操作实例详解

unittest+coverage单元测试代码覆盖操作实例详解

基于上一篇文章,这篇文章是关于使用coverage来实现代码覆盖的操作实例,源代码在上一篇已经给出相应链接。 本篇文章字用来实现代码覆盖的源代码,整个项目的测试框架如下: 就是在源代码...

python快排算法详解

python快排算法详解

快排是python经典算法之一。 1、下面讲解的是什么是快排和快排的图示。 2、快排是一种解决排序问题的运算方法。 3、快排的原理:在数组中任意选择一个数字作为基准,用数组的数据和基...

Win10下python 2.7.13 安装配置方法图文教程

Win10下python 2.7.13 安装配置方法图文教程

本文记录了Windows10安装Python2.7的详细步骤,分享给大家。 一、下载软件 Python的官方地址 点击Downloads找到进行下载 点击进行下载、有18M左右 下...

Python模拟登陆实现代码

Python模拟登陆实现代码

下面分享一个使用Python进行网站模拟登陆的小例子。 原理 使用Cookie技术,绕开网站登录验证。要使用到cookielib库。流程: 创建一个保存Cookie的容器,可选的有...

python dict.get()和dict['key']的区别详解

先看代码: In [1]: a = {'name': 'wang'} In [2]: a.get('age') In [3]: a['age'] -----------...