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使用py2neo操作图数据库neo4j的方法详解

Python使用py2neo操作图数据库neo4j的方法详解

本文实例讲述了Python使用py2neo操作图数据库neo4j的方法。分享给大家供大家参考,具体如下: 1、概念 图:数据结构中的图由节点和其之间的边组成。节点表示一个实体,边表示实体...

python 执行shell命令并将结果保存的实例

方法1: 将shell执行的结果保存到字符串 def run_cmd(cmd): result_str='' process = subprocess.Popen(cmd, sh...

详解python3中tkinter知识点

#导入tkinter模块,以及导入ttk模块,tkinter是python结合tk的标准接口,ttk是TK8.5之后加入的“主题化工具包” from tkinter import *...

PyQt5使用QTimer实现电子时钟

PyQt5使用QTimer实现电子时钟

本文用 PyQt5 的QTimer类的两种方式实现电子时钟,供大家参考,具体内容如下 【效果图】 【知识点】 QTimer类提供了定时器信号/槽和单触发定时器。 它在内部使用定时器事件...

python pandas库中DataFrame对行和列的操作实例讲解

用pandas中的DataFrame时选取行或列: import numpy as np import pandas as pd from pandas import Sereis,...