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 Web框架Flask中使用七牛云存储实例

对于小型站点,使用七牛云存储的免费配额已足够为站点提供稳定、快速的存储服务 七牛云存储已有Python SDK,对它进行简单封装后,就可以直接在Flask中使用了,项目代码见GitHub...

深入解析Python中的WSGI接口

概述 WSGI接口包含两方面:server/gateway 及 application/framework。 server调用由application提供的可调用对象。 另外在serve...

基于ID3决策树算法的实现(Python版)

基于ID3决策树算法的实现(Python版)

实例如下: # -*- coding:utf-8 -*- from numpy import * import numpy as np import pandas as pd fr...

python调用支付宝支付接口流程

python调用支付宝支付接口流程

项目演示: 一、输入金额 二、跳转到支付宝付款 三、支付成功 四、跳转回自己网站 在使用支付宝接口的前期准备: 1、支付宝公钥 2、应用公钥 3、应用私钥 4、APPID 5、D...

python实现京东订单推送到测试环境,提供便利操作示例

本文实例讲述了python实现京东订单推送到测试环境,提供便利操作。分享给大家供大家参考,具体如下: # -*- coding: utf-8 -*- import hashlib i...