X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/095315e20d117d292ea01f8f964b19c032a0fd56..68fc5c8025e38b9d827383fbfe7ce509ae331c1f:/wxPython/demo/MediaCtrl.py diff --git a/wxPython/demo/MediaCtrl.py b/wxPython/demo/MediaCtrl.py index 30dc03b1fc..1a774ed81c 100644 --- a/wxPython/demo/MediaCtrl.py +++ b/wxPython/demo/MediaCtrl.py @@ -5,6 +5,18 @@ import os #---------------------------------------------------------------------- +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) + +#---------------------------------------------------------------------- + class TestPanel(wx.Panel): def __init__(self, parent, log): self.log = log @@ -13,16 +25,23 @@ class TestPanel(wx.Panel): # 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) @@ -35,9 +54,9 @@ class TestPanel(wx.Panel): 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 @@ -53,8 +72,8 @@ class TestPanel(wx.Panel): sizer.Add(self.st_pos, (3, 5)) self.SetSizer(sizer) - self.DoLoadFile(os.path.abspath("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) @@ -73,20 +92,30 @@ class TestPanel(wx.Panel): 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.mc.Play() self.slider.SetRange(0, self.mc.Length()) - + + 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() @@ -105,6 +134,9 @@ class TestPanel(wx.Panel): 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 #---------------------------------------------------------------------- @@ -148,4 +180,3 @@ if __name__ == '__main__': import sys,os import run run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:]) -