【脚本语言系列】关于Python音频处理WMPlayerOCX,你需要知道的事情

来源:互联网 发布:飞狐软件免费吗 编辑:程序博客网 时间:2024/05/29 09:08

如何使用WMPlayerOCX

# -*- coding:utf-8 -*-#import Tkinterimport tkFileDialogfrom win32com.client import Dispatchclass 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组件来播放音频文件。

阅读全文
0 0
原创粉丝点击