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

相关文章

Windows平台Python编程必会模块之pywin32介绍

Windows平台Python编程必会模块之pywin32介绍

在Windows平台上,从原来使用C/C++编写原生EXE程序,到使用Python编写一些常用脚本程序,成熟的模块的使用使得编程效率大大提高了。 不过,python模块虽多,也不可能满足...

浅谈Python中函数的定义及其调用方法

浅谈Python中函数的定义及其调用方法

一、函数的定义及其应用 所谓函数,就是把具有独立功能的代码块组织成为一个小模块,在需要的时候调用函数的使用包含两个步骤 1.定义函数–封装独立的功能 2.调用函数–享受封装的成果...

python 根据字典的键值进行排序的方法

python 根据字典的键值进行排序的方法

1、利用key排序 d = {'d1':2, 'd2':4, 'd4':1,'d3':3,} for k in sorted(d): print(k,d[k]) d1 2 d2...

Python for Informatics 第11章之正则表达式(二)

注:以下文章原文来自于Dr Charles Severance 的 《Python for Informatics》 11.1 正则表达式的字符匹配   我们可以用许多其它的特殊字符...

python随机生成指定长度密码的方法

本文实例讲述了python随机生成指定长度密码的方法。分享给大家供大家参考。具体如下: 下面的python代码通过对各种字符进行随机组合生成一个指定长度的随机密码 python中的str...