2004-11-24 14:21:30 -05:00
|
|
|
|
|
|
|
import wx
|
|
|
|
import wx.media
|
|
|
|
import os
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
2006-01-17 00:42:30 -05:00
|
|
|
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)
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
2004-11-24 14:21:30 -05:00
|
|
|
class TestPanel(wx.Panel):
|
|
|
|
def __init__(self, parent, log):
|
|
|
|
self.log = log
|
|
|
|
wx.Panel.__init__(self, parent, -1,
|
|
|
|
style=wx.TAB_TRAVERSAL|wx.CLIP_CHILDREN)
|
|
|
|
|
|
|
|
# Create some controls
|
2005-02-02 17:36:36 -05:00
|
|
|
try:
|
2006-11-05 20:15:35 -05:00
|
|
|
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
|
|
|
|
)
|
2005-02-02 17:36:36 -05:00
|
|
|
except NotImplementedError:
|
|
|
|
self.Destroy()
|
|
|
|
raise
|
2004-11-24 14:21:30 -05:00
|
|
|
|
2006-01-17 00:42:30 -05:00
|
|
|
self.Bind(wx.media.EVT_MEDIA_LOADED, self.OnMediaLoaded)
|
|
|
|
|
2004-11-24 14:21:30 -05:00
|
|
|
btn1 = wx.Button(self, -1, "Load File")
|
|
|
|
self.Bind(wx.EVT_BUTTON, self.OnLoadFile, btn1)
|
|
|
|
|
2004-12-08 16:49:41 -05:00
|
|
|
btn2 = wx.Button(self, -1, "Play")
|
|
|
|
self.Bind(wx.EVT_BUTTON, self.OnPlay, btn2)
|
2006-01-17 00:42:30 -05:00
|
|
|
self.playBtn = btn2
|
2004-11-24 14:21:30 -05:00
|
|
|
|
2004-12-08 16:49:41 -05:00
|
|
|
btn3 = wx.Button(self, -1, "Pause")
|
|
|
|
self.Bind(wx.EVT_BUTTON, self.OnPause, btn3)
|
2004-11-24 14:21:30 -05:00
|
|
|
|
2004-12-08 16:49:41 -05:00
|
|
|
btn4 = wx.Button(self, -1, "Stop")
|
|
|
|
self.Bind(wx.EVT_BUTTON, self.OnStop, btn4)
|
|
|
|
|
2004-12-23 19:43:24 -05:00
|
|
|
slider = wx.Slider(self, -1, 0, 0, 0)
|
|
|
|
self.slider = slider
|
2006-01-06 02:05:15 -05:00
|
|
|
slider.SetMinSize((150, -1))
|
2004-12-23 19:43:24 -05:00
|
|
|
self.Bind(wx.EVT_SLIDER, self.OnSeek, slider)
|
|
|
|
|
2006-01-17 00:42:30 -05:00
|
|
|
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))
|
2004-12-23 19:43:24 -05:00
|
|
|
|
|
|
|
|
2004-11-24 14:21:30 -05:00
|
|
|
# setup the layout
|
|
|
|
sizer = wx.GridBagSizer(5,5)
|
|
|
|
sizer.Add(self.mc, (1,1), span=(5,1))#, flag=wx.EXPAND)
|
|
|
|
sizer.Add(btn1, (1,3))
|
|
|
|
sizer.Add(btn2, (2,3))
|
|
|
|
sizer.Add(btn3, (3,3))
|
|
|
|
sizer.Add(btn4, (4,3))
|
2004-12-23 19:43:24 -05:00
|
|
|
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))
|
2004-11-24 14:21:30 -05:00
|
|
|
self.SetSizer(sizer)
|
2004-12-23 19:43:24 -05:00
|
|
|
|
2006-01-17 00:42:30 -05:00
|
|
|
#self.DoLoadFile(os.path.abspath("data/testmovie.mpg"))
|
|
|
|
wx.CallAfter(self.DoLoadFile, os.path.abspath("data/testmovie.mpg"))
|
2004-12-23 19:43:24 -05:00
|
|
|
|
|
|
|
self.timer = wx.Timer(self)
|
|
|
|
self.Bind(wx.EVT_TIMER, self.OnTimer)
|
|
|
|
self.timer.Start(100)
|
|
|
|
|
2004-11-24 14:21:30 -05:00
|
|
|
|
|
|
|
|
|
|
|
def OnLoadFile(self, evt):
|
|
|
|
dlg = wx.FileDialog(self, message="Choose a media file",
|
|
|
|
defaultDir=os.getcwd(), defaultFile="",
|
|
|
|
style=wx.OPEN | wx.CHANGE_DIR )
|
|
|
|
if dlg.ShowModal() == wx.ID_OK:
|
|
|
|
path = dlg.GetPath()
|
2004-12-23 19:43:24 -05:00
|
|
|
self.DoLoadFile(path)
|
2004-11-24 14:21:30 -05:00
|
|
|
dlg.Destroy()
|
2004-12-23 19:43:24 -05:00
|
|
|
|
|
|
|
|
|
|
|
def DoLoadFile(self, path):
|
2006-01-17 00:42:30 -05:00
|
|
|
self.playBtn.Disable()
|
2006-02-13 14:19:39 -05:00
|
|
|
#noLog = wx.LogNull()
|
2004-12-23 19:43:24 -05:00
|
|
|
if not self.mc.Load(path):
|
|
|
|
wx.MessageBox("Unable to load %s: Unsupported format?" % path,
|
|
|
|
"ERROR",
|
|
|
|
wx.ICON_ERROR | wx.OK)
|
|
|
|
else:
|
2006-10-31 03:50:17 -05:00
|
|
|
self.mc.SetInitialSize()
|
2004-12-23 19:43:24 -05:00
|
|
|
self.GetSizer().Layout()
|
2006-01-06 02:05:15 -05:00
|
|
|
self.slider.SetRange(0, self.mc.Length())
|
2006-01-17 00:42:30 -05:00
|
|
|
|
|
|
|
def OnMediaLoaded(self, evt):
|
|
|
|
self.playBtn.Enable()
|
2004-11-24 14:21:30 -05:00
|
|
|
|
|
|
|
def OnPlay(self, evt):
|
2006-01-17 00:42:30 -05:00
|
|
|
if not self.mc.Play():
|
|
|
|
wx.MessageBox("Unable to Play media : Unsupported format?",
|
|
|
|
"ERROR",
|
|
|
|
wx.ICON_ERROR | wx.OK)
|
|
|
|
else:
|
2006-10-31 03:50:17 -05:00
|
|
|
self.mc.SetInitialSize()
|
2006-07-10 13:02:25 -04:00
|
|
|
self.GetSizer().Layout()
|
2006-01-17 00:42:30 -05:00
|
|
|
self.slider.SetRange(0, self.mc.Length())
|
|
|
|
|
2004-11-24 14:21:30 -05:00
|
|
|
def OnPause(self, evt):
|
|
|
|
self.mc.Pause()
|
|
|
|
|
|
|
|
def OnStop(self, evt):
|
|
|
|
self.mc.Stop()
|
|
|
|
|
|
|
|
|
2004-12-23 19:43:24 -05:00
|
|
|
def OnSeek(self, evt):
|
|
|
|
offset = self.slider.GetValue()
|
|
|
|
self.mc.Seek(offset)
|
|
|
|
|
|
|
|
def OnTimer(self, evt):
|
|
|
|
offset = self.mc.Tell()
|
|
|
|
self.slider.SetValue(offset)
|
|
|
|
self.st_size.SetLabel('size: %s' % self.mc.GetBestSize())
|
|
|
|
self.st_len.SetLabel('length: %d seconds' % (self.mc.Length()/1000))
|
|
|
|
self.st_pos.SetLabel('position: %d' % offset)
|
2004-11-24 14:21:30 -05:00
|
|
|
|
2006-02-13 14:19:39 -05:00
|
|
|
def ShutdownDemo(self):
|
|
|
|
self.timer.Stop()
|
|
|
|
del self.timer
|
2004-11-24 14:21:30 -05:00
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
|
|
def runTest(frame, nb, log):
|
|
|
|
try:
|
|
|
|
win = TestPanel(nb, log)
|
|
|
|
return win
|
|
|
|
except NotImplementedError:
|
|
|
|
from Main import MessagePanel
|
|
|
|
win = MessagePanel(nb, 'wx.MediaCtrl is not available on this platform.',
|
|
|
|
'Sorry', wx.ICON_WARNING)
|
|
|
|
return win
|
|
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
overview = """<html><body>
|
|
|
|
<h2><center>wx.MediaCtrl</center></h2>
|
|
|
|
|
2004-12-23 19:43:24 -05:00
|
|
|
wx.MediaCtrl is a class that allows a way to convieniently display
|
|
|
|
various types of media, such as videos, audio files, natively through
|
|
|
|
native codecs. Several different formats of audio and video files are
|
|
|
|
supported, but some formats may not be playable on all platforms or
|
|
|
|
may require specific codecs to be installed.
|
2004-11-24 14:49:08 -05:00
|
|
|
|
|
|
|
<p>
|
|
|
|
wx.MediaCtrl uses native backends to render media, for example on Windows
|
|
|
|
there is a ActiveMovie/DirectShow backend, and on Macintosh there is a
|
|
|
|
QuickTime backend.
|
|
|
|
<p>
|
|
|
|
wx.MediaCtrl is not currently available on unix systems.
|
|
|
|
|
2004-11-24 14:21:30 -05:00
|
|
|
</body></html>
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys,os
|
|
|
|
import run
|
|
|
|
run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
|