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 十六进制整数与ASCii编码字符串相互转换方法

在使用Pyserial与STM32进行通讯时,遇到了需要将十六进制整数以Ascii码编码的字符串进行发送并且将接收到的Ascii码编码的字符串转换成十六进制整型的问题。查阅网上的资料后,...

Django使用详解:ORM 的反向查找(related_name)

先定义两个模型,一个是A,一个是B,是一对多的类型。 class A(models.Model): name= models.CharField('名称', max_length...

Numpy将二维数组添加到空数组的实现

使用append函数将一个二维数组添加到一个空数组,关键是维度要对的上 a=np.empty([0,3]) b = np.array([[1,2,3],[4,5,6]]) c=[[7...

Python实现点云投影到平面显示

值得学习的地方: 1.选择合法索引的方式 2.数组转图像显示 import numpy as np from PIL import Image #input : shape(N,...

OpenCV 轮廓检测的实现方法

OpenCV 轮廓检测的实现方法

轮廓概述 轮廓可以简单认为成将连续的点(连着边界)连在一起的曲线,具有相同的颜色或者灰度。轮廓在形状分析和物体的检测和识别中很有用。  为了更加准确,要使用二值化图像...