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

相关文章

Python使用urllib模块的urlopen超时问题解决方法

在新的公司开始上班,今天工作的主题内容是市场部门需要抓取一些论坛用户的邮箱,以便发送营销邮件。 于是用了一个python脚本来执行,前面抓了几个都没有什么问题,后来碰到一个论坛,在执行u...

python 链接和操作 memcache方法

1,打开memcached服务 memcached -m 10 -p 12000 2,使用python-memcached模块,进行简单的链接和存取数据 import me...

Python实现统计英文文章词频的方法分析

本文实例讲述了Python实现统计英文文章词频的方法。分享给大家供大家参考,具体如下: 应用介绍: 统计英文文章词频是很常见的需求,本文利用python实现。 思路分析: 1、把英文文章...

python使用fork实现守护进程的方法

os模块中的fork方法可以创建一个子进程。相当于克隆了父进程 os.fork() 子进程运行时,os.fork方法会返回0;  而父进程运行时,os.fork方法会返回子进程...

python写程序统计词频的方法

python写程序统计词频的方法

在李笑来所著《时间当作朋友》中有这么一段: 可问题在于,当年我在少年宫学习计算机程序语言的时候,怎么可能想象得到,在20多年后的某一天,我需要先用软件调取语料库中的数据,然后用统计方法为...