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 tkinter实现界面切换的示例代码

python tkinter实现界面切换的示例代码

跳转实现思路 主程序相当于桌子: import tkinter as tk root = tk.Tk() 而不同的Frame相当于不同的桌布: face1 = tk....

详解centos7+django+python3+mysql+阿里云部署项目全流程

详解centos7+django+python3+mysql+阿里云部署项目全流程

(PS:本文假设你已经在本地联调好django和客户端,只是需要将django部署到外网) 购买阿里云服务器 到[阿里云官网],选择轻量应用服务器, 步骤如图所示: 地域随便选...

python 实现在txt指定行追加文本的方法

如下所示: fp = file('data.txt') lines = [] for line in fp: lines.append(line) fp.close() l...

python开发之函数定义实例分析

本文实例讲述了python开发之函数定义方法。分享给大家供大家参考,具体如下: 下面是我做的几个用列: #python中的函数定义,使用和传参 def_str = '''\ py...

python处理csv数据的方法

本文实例讲述了python处理csv数据的方法。分享给大家供大家参考。具体如下: Python代码: 复制代码 代码如下: #coding=utf-8 __author__ = 'deh...