]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/MediaCtrl.py
REWRITE wxStringBase::append and wxString::Replace.
[wxWidgets.git] / wxPython / demo / MediaCtrl.py
CommitLineData
256c055e
RD
1
2import wx
3import wx.media
4import os
5
95262b5f
RD
6from Main import opj
7
256c055e
RD
8#----------------------------------------------------------------------
9
10class TestPanel(wx.Panel):
11 def __init__(self, parent, log):
12 self.log = log
13 wx.Panel.__init__(self, parent, -1,
14 style=wx.TAB_TRAVERSAL|wx.CLIP_CHILDREN)
15
16 # Create some controls
a7593631
RD
17 try:
18 self.mc = wx.media.MediaCtrl(self, style=wx.SIMPLE_BORDER)
19 except NotImplementedError:
20 self.Destroy()
21 raise
256c055e
RD
22
23 btn1 = wx.Button(self, -1, "Load File")
24 self.Bind(wx.EVT_BUTTON, self.OnLoadFile, btn1)
25
95262b5f
RD
26 btn2 = wx.Button(self, -1, "Play")
27 self.Bind(wx.EVT_BUTTON, self.OnPlay, btn2)
256c055e 28
95262b5f
RD
29 btn3 = wx.Button(self, -1, "Pause")
30 self.Bind(wx.EVT_BUTTON, self.OnPause, btn3)
256c055e 31
95262b5f
RD
32 btn4 = wx.Button(self, -1, "Stop")
33 self.Bind(wx.EVT_BUTTON, self.OnStop, btn4)
34
35 btn5 = wx.ToggleButton(self, -1, "Loop")
36 self.Bind(wx.EVT_TOGGLEBUTTON, self.OnLoopToggle, btn5)
256c055e 37
d6660ffa
RD
38 slider = wx.Slider(self, -1, 0, 0, 0)
39 self.slider = slider
40 self.Bind(wx.EVT_SLIDER, self.OnSeek, slider)
41
42 self.st_size = wx.StaticText(self, -1, size=(100,-1))
43 self.st_len = wx.StaticText(self, -1, size=(100,-1))
44 self.st_pos = wx.StaticText(self, -1, size=(100,-1))
45
46
256c055e
RD
47 # setup the layout
48 sizer = wx.GridBagSizer(5,5)
49 sizer.Add(self.mc, (1,1), span=(5,1))#, flag=wx.EXPAND)
50 sizer.Add(btn1, (1,3))
51 sizer.Add(btn2, (2,3))
52 sizer.Add(btn3, (3,3))
53 sizer.Add(btn4, (4,3))
54 sizer.Add(btn5, (5,3))
d6660ffa
RD
55 sizer.Add(slider, (6,1), flag=wx.EXPAND)
56 sizer.Add(self.st_size, (1, 5))
57 sizer.Add(self.st_len, (2, 5))
58 sizer.Add(self.st_pos, (3, 5))
256c055e 59 self.SetSizer(sizer)
d6660ffa
RD
60
61 self.DoLoadFile(opj("data/testmovie.mpg"))
62 self.mc.Stop()
63
64 self.timer = wx.Timer(self)
65 self.Bind(wx.EVT_TIMER, self.OnTimer)
66 self.timer.Start(100)
67
256c055e
RD
68
69
70 def OnLoadFile(self, evt):
71 dlg = wx.FileDialog(self, message="Choose a media file",
72 defaultDir=os.getcwd(), defaultFile="",
73 style=wx.OPEN | wx.CHANGE_DIR )
74 if dlg.ShowModal() == wx.ID_OK:
75 path = dlg.GetPath()
d6660ffa 76 self.DoLoadFile(path)
256c055e 77 dlg.Destroy()
d6660ffa
RD
78
79
80 def DoLoadFile(self, path):
81 if not self.mc.Load(path):
82 wx.MessageBox("Unable to load %s: Unsupported format?" % path,
83 "ERROR",
84 wx.ICON_ERROR | wx.OK)
85 else:
86 self.mc.SetBestFittingSize()
87 self.GetSizer().Layout()
88 self.slider.SetRange(0, self.mc.Length())
89 self.mc.Play()
256c055e
RD
90
91
95262b5f
RD
92 def OnLoopToggle(self, evt):
93 btn = evt.GetEventObject()
94 self.mc.Loop(btn.GetValue())
95
256c055e
RD
96
97 def OnPlay(self, evt):
98 self.mc.Play()
99
100 def OnPause(self, evt):
101 self.mc.Pause()
102
103 def OnStop(self, evt):
104 self.mc.Stop()
105
106
d6660ffa
RD
107 def OnSeek(self, evt):
108 offset = self.slider.GetValue()
109 self.mc.Seek(offset)
110
111 def OnTimer(self, evt):
112 offset = self.mc.Tell()
113 self.slider.SetValue(offset)
114 self.st_size.SetLabel('size: %s' % self.mc.GetBestSize())
115 self.st_len.SetLabel('length: %d seconds' % (self.mc.Length()/1000))
116 self.st_pos.SetLabel('position: %d' % offset)
256c055e
RD
117
118
119#----------------------------------------------------------------------
120
121def runTest(frame, nb, log):
122 try:
123 win = TestPanel(nb, log)
124 return win
125 except NotImplementedError:
126 from Main import MessagePanel
127 win = MessagePanel(nb, 'wx.MediaCtrl is not available on this platform.',
128 'Sorry', wx.ICON_WARNING)
129 return win
130
131
132#----------------------------------------------------------------------
133
134
135
136overview = """<html><body>
137<h2><center>wx.MediaCtrl</center></h2>
138
d6660ffa
RD
139wx.MediaCtrl is a class that allows a way to convieniently display
140various types of media, such as videos, audio files, natively through
141native codecs. Several different formats of audio and video files are
142supported, but some formats may not be playable on all platforms or
143may require specific codecs to be installed.
9828eeb4
RD
144
145<p>
146wx.MediaCtrl uses native backends to render media, for example on Windows
147there is a ActiveMovie/DirectShow backend, and on Macintosh there is a
148QuickTime backend.
149<p>
150wx.MediaCtrl is not currently available on unix systems.
151
256c055e
RD
152</body></html>
153"""
154
155
156
157if __name__ == '__main__':
158 import sys,os
159 import run
160 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
161