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之当你发现QTimer不能用时的解决方法

如下所示: # -*- coding: utf-8 -*- import numpy as np from PyQt5.QtCore import QTimer, QObject...

在Python中处理列表之reverse()方法的使用教程

 reverse()方法代替逆转列表对象。 语法 以下是reverse()方法的语法: list.reverse() 参数    ...

Dlib+OpenCV深度学习人脸识别的方法示例

Dlib+OpenCV深度学习人脸识别的方法示例

前言 人脸识别在LWF(Labeled Faces in the Wild)数据集上人脸识别率现在已经99.7%以上,这个识别率确实非常高了,但是真实的环境中的准确率有多少呢?我没有这方...

Python实现bilibili时间长度查询的示例代码

Python实现bilibili时间长度查询的示例代码

说明:最近在B站看一些材料力学视频时候,感觉有一些分集狂魔的分集真的很恐怖,有的甚至上百集,因此决定写个小脚本每次分析下到底这个系列视频到底有多长。 好了,下面是分析过程: 第一步当然...

python+matplotlib实现礼盒柱状图实例代码

python+matplotlib实现礼盒柱状图实例代码

演示结果: 完整代码: import matplotlib.pyplot as plt import numpy as np from matplotlib.image impor...