import wx.media
import os
-from Main import opj
+#----------------------------------------------------------------------
+
+class StaticText(wx.StaticText):
+ """
+ A StaticText that only updates the label if it has changed, to
+ help reduce potential flicker since these controls would be
+ updated very frequently otherwise.
+ """
+ def SetLabel(self, label):
+ if label <> self.GetLabel():
+ wx.StaticText.SetLabel(self, label)
#----------------------------------------------------------------------
# Create some controls
try:
- self.mc = wx.media.MediaCtrl(self, style=wx.SIMPLE_BORDER)
+ self.mc = wx.media.MediaCtrl(self, style=wx.SIMPLE_BORDER,
+ #szBackend=wx.media.MEDIABACKEND_DIRECTSHOW
+ #szBackend=wx.media.MEDIABACKEND_QUICKTIME
+ #szBackend=wx.media.MEDIABACKEND_WMP10
+ )
except NotImplementedError:
self.Destroy()
raise
+ self.Bind(wx.media.EVT_MEDIA_LOADED, self.OnMediaLoaded)
+
btn1 = wx.Button(self, -1, "Load File")
self.Bind(wx.EVT_BUTTON, self.OnLoadFile, btn1)
btn2 = wx.Button(self, -1, "Play")
self.Bind(wx.EVT_BUTTON, self.OnPlay, btn2)
+ self.playBtn = btn2
btn3 = wx.Button(self, -1, "Pause")
self.Bind(wx.EVT_BUTTON, self.OnPause, btn3)
btn4 = wx.Button(self, -1, "Stop")
self.Bind(wx.EVT_BUTTON, self.OnStop, btn4)
- btn5 = wx.ToggleButton(self, -1, "Loop")
- self.Bind(wx.EVT_TOGGLEBUTTON, self.OnLoopToggle, btn5)
-
slider = wx.Slider(self, -1, 0, 0, 0)
self.slider = slider
+ slider.SetMinSize((150, -1))
self.Bind(wx.EVT_SLIDER, self.OnSeek, slider)
- self.st_size = wx.StaticText(self, -1, size=(100,-1))
- self.st_len = wx.StaticText(self, -1, size=(100,-1))
- self.st_pos = wx.StaticText(self, -1, size=(100,-1))
+ self.st_size = StaticText(self, -1, size=(100,-1))
+ self.st_len = StaticText(self, -1, size=(100,-1))
+ self.st_pos = StaticText(self, -1, size=(100,-1))
# setup the layout
sizer.Add(btn2, (2,3))
sizer.Add(btn3, (3,3))
sizer.Add(btn4, (4,3))
- sizer.Add(btn5, (5,3))
sizer.Add(slider, (6,1), flag=wx.EXPAND)
sizer.Add(self.st_size, (1, 5))
sizer.Add(self.st_len, (2, 5))
sizer.Add(self.st_pos, (3, 5))
self.SetSizer(sizer)
- self.DoLoadFile(opj("data/testmovie.mpg"))
- self.mc.Stop()
+ #self.DoLoadFile(os.path.abspath("data/testmovie.mpg"))
+ wx.CallAfter(self.DoLoadFile, os.path.abspath("data/testmovie.mpg"))
self.timer = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.OnTimer)
def DoLoadFile(self, path):
+ self.playBtn.Disable()
+ #noLog = wx.LogNull()
if not self.mc.Load(path):
wx.MessageBox("Unable to load %s: Unsupported format?" % path,
"ERROR",
wx.ICON_ERROR | wx.OK)
else:
- self.mc.SetBestFittingSize()
+ self.mc.SetInitialSize()
self.GetSizer().Layout()
self.slider.SetRange(0, self.mc.Length())
- self.mc.Play()
-
-
- def OnLoopToggle(self, evt):
- btn = evt.GetEventObject()
- self.mc.Loop(btn.GetValue())
-
+
+ def OnMediaLoaded(self, evt):
+ self.playBtn.Enable()
def OnPlay(self, evt):
- self.mc.Play()
-
+ if not self.mc.Play():
+ wx.MessageBox("Unable to Play media : Unsupported format?",
+ "ERROR",
+ wx.ICON_ERROR | wx.OK)
+ else:
+ self.mc.SetInitialSize()
+ self.GetSizer().Layout()
+ self.slider.SetRange(0, self.mc.Length())
+
def OnPause(self, evt):
self.mc.Pause()
self.st_len.SetLabel('length: %d seconds' % (self.mc.Length()/1000))
self.st_pos.SetLabel('position: %d' % offset)
+ def ShutdownDemo(self):
+ self.timer.Stop()
+ del self.timer
#----------------------------------------------------------------------
import sys,os
import run
run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
-