Created
November 16, 2009 03:43
-
-
Save lqc/235708 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Minimal media player using wxWidgets | |
import wx | |
from wx.media import * | |
import os | |
class PlayerView(wx.Frame): | |
def __init__(self): | |
super(PlayerView, self).__init__(None, -1, "LamePlayer", wx.DefaultPosition ) | |
self.panel = wx.Panel(self, -1, style=wx.SUNKEN_BORDER) | |
# Layout | |
box = wx.BoxSizer( wx.SB_VERTICAL ) | |
self.file_picker = wx.FilePickerCtrl(self.panel, -1) | |
box.Add(self.file_picker, 0, wx.EXPAND) | |
box.AddStretchSpacer() | |
hbox = wx.BoxSizer( wx.SB_HORIZONTAL ) | |
self.buttons = { | |
'play': wx.Button(self.panel, label="Play"), | |
'stop': wx.Button(self.panel, label="Stop"), | |
} | |
box.Add(hbox, 0) | |
for b in self.buttons.values(): | |
hbox.Add(b, 1, wx.EXPAND) | |
hbox.AddStretchSpacer() | |
self.panel.SetSizer(box) | |
# Bind event handlers | |
self.Bind(wx.EVT_BUTTON, self.current_play_or_pause, self.buttons['play']) | |
self.Bind(wx.EVT_BUTTON, self.current_stop, self.buttons['stop']) | |
self.Bind(wx.EVT_FILEPICKER_CHANGED, self.change_current, self.file_picker) | |
self.current_media = MediaCtrl(self.panel, -1, "") | |
print self.current_media | |
def current_play_or_pause(self, event): | |
if self.current_media.GetState() == MEDIASTATE_PLAYING: | |
self.current_media.Pause() | |
self.buttons['play'].SetLabel('Play') | |
else: | |
self.current_media.Play() | |
self.buttons['play'].SetLabel('Pause') | |
def current_stop(self, event=None): | |
self.current_media.Stop() | |
self.buttons['play'].SetLabel('Play') | |
def change_current(self, event): | |
self.current_stop() | |
filename = self.file_picker.GetPath() | |
self.current_media.Load(filename) | |
class PlayerApp(wx.App): | |
def OnInit(self): | |
frame = PlayerView() | |
frame.Show(True) | |
self.SetTopWindow(frame) | |
return True | |
if __name__ == '__main__': | |
app = PlayerApp(0) | |
app.MainLoop() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment