【脚本语言系列】关于Python音频处理WMPlayerOCX,你需要知道的事情
2017-05-21 18:33
961 查看
如何使用WMPlayerOCX
# -*- coding:utf-8 -*- # import Tkinter import tkFileDialog from win32com.client import Dispatch class Window: def __init__(self): self.root = root = Tkinter.Tk() buttonAdd = Tkinter.Button(root, text = 'Add', command = self.add) buttonAdd.place(x = 150, y = 15) buttonPlay = Tkinter.Button(root, text = 'Play', command = self.play) buttonPlay.place(x = 200, y = 15) buttonPause = Tkinter.Button(root, text = 'Pause', command = self.pause) buttonPause.place(x = 250, y = 15) buttonStop = Tkinter.Button(root, text = 'Stop', command = self.stop) buttonStop.place(x = 300, y = 15) buttonNext = Tkinter.Button(root, text = 'Next', command = self.next) buttonNext.place(x = 350, y = 15) frame = Tkinter.Frame(root, bd = 2) self.playList = Tkinter.Text(frame) scrollbar = Tkinter.Scrollbar(frame) scrollbar.config(command = self.playList.yview) self.playList.pack(side = Tkinter.LEFT) scrollbar.pack(side=Tkinter.RIGHT, fill=Tkinter.Y) frame.place(y = 50) self.wmp = Dispatch('WMPlayer.OCX') def MainLoop(self): self.root.minsize(510,380) self.root.maxsize(510,380) self.root.mainloop() def add(self): file = tkFileDialog.askopenfilename(title = 'Python Music Player', filetypes = [('MP3', '*.mp3'),('WMA', '*.wma'),('WAV','.wav')]) if file: media = self.wmp.newMedia(file) self.wmp.currentPlaylist.appendItem(media) self.playList.insert(Tkinter.END, file+'\n') def play(self): self.wmp.controls.play() def pause(self): self.wmp.controls.pause() def next(self): self.wmp.controls.next() def stop(self): self.wmp.controls.stop() window = Window() window.MainLoop()
1. 增加音频文件
2. 点击播放音频文件
3. 暂停/停止播放音频文件
4. 播放下个音频文件
什么是WMPlayerOCX
由于PythonWin提供了对COM组件的支持,因此可以在Python中直接使用WMPlayer.OCX组件来播放音频文件。相关文章推荐
- 【脚本语言系列】关于Python音频处理DirectSound, 你需要知道的事
- 【脚本语言系列】关于Python结构化文本文件处理xml,你需要知道的事
- 【脚本语言系列】关于Python结构化文本文件处理JSON,你需要知道的事
- 【脚本语言系列】关于Python机器学习,你需要知道的事情
- 【脚本语言系列】关于Python结构化文本文件处理Thrift,你需要知道的事
- 【脚本语言系列】关于Python结构化文本文件处理MsgPack,你需要知道的事
- 【脚本语言系列】关于Python结构化文本文件处理HTML,你需要知道的事
- 【脚本语言系列】关于Python结构化文本文件处理Avro,你需要知道的事
- 【脚本语言系列】关于Python基础知识异常处理,你需要知道的事
- 【脚本语言系列】关于Python结构化二进制文件处理Microsoft Excel,你需要知道的事
- 【脚本语言系列】关于Python图像处理PIL,你需要知道的事
- 【脚本语言系列】关于Python数据库处理SQLAlchemy,你需要知道的事
- 【脚本语言系列】关于PythonNoSQL数据库处理memcached,你需要知道的事
- 【脚本语言系列】关于Python异常处理,你需要知道的事
- 【脚本语言系列】关于PythonNoSQL数据库处理redis,你需要知道的事
- 【脚本语言系列】关于Python图像处理scikits-image, 需要知道的事
- 【脚本语言系列】关于Python结构化文本文件处理YAML,你需要知道的事
- 【脚本语言系列】关于Python结构化文本文件处理csv,你需要知道的事
- 【脚本语言系列】关于 Python XML处理,你需要知道的事
- 【脚本语言系列】关于Python数据库处理SQLite,你需要知道的事