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