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

相关文章

Tensorflow读取并输出已保存模型的权重数值方式

这篇文章是为了对网络模型的权重输出,可以用来转换成其他框架的模型。 import tensorflow as tf from tensorflow.python import pyw...

Python基于回溯法子集树模板解决旅行商问题(TSP)实例

Python基于回溯法子集树模板解决旅行商问题(TSP)实例

本文实例讲述了Python基于回溯法子集树模板解决旅行商问题(TSP)。分享给大家供大家参考,具体如下: 问题 旅行商问题(Traveling Salesman Problem,TSP)...

python开发之tkinter实现图形随鼠标移动的方法

python开发之tkinter实现图形随鼠标移动的方法

本文实例讲述了python开发之tkinter实现图形随鼠标移动的方法。分享给大家供大家参考,具体如下: 做这个东西的时候,灵感源自于一个js效果: 两个眼睛随鼠标移动而移动 运行效果:...

Python安装lz4-0.10.1遇到的坑

因为项目的需求,要 lz4.0.10.1 的,因为本机已经有一个 1.1.0 版本的,所以必须先卸掉,然后我差点没疯了(手动微笑) sudo pip uninstall lz4 Un...

python 测试实现方法

 1)doctest 使用doctest是一种类似于命令行尝试的方式,用法很简单,如下 复制代码 代码如下:def f(n): """ >>> f(1) 1...