]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/tests/test_mediaCtrl.py
3 from wx
.lib
.mixins
.inspection
import InspectableApp
5 import os
; print os
.getpid(); raw_input("press enter...")
7 class TestFrame(wx
.Frame
):
8 def __init__(self
, *args
, **kw
):
9 wx
.Frame
.__init
__(self
, *args
, **kw
)
10 self
.CreateStatusBar()
13 self
.mc
= wx
.media
.MediaCtrl(pnl
, size
=(-1,200))
14 #self.fn = "/home/robind/smb4k/BEAST/MyVideos/SageTV/48HoursMystery-6199728-0.mpg"
16 self
.Bind(wx
.media
.EVT_MEDIA_PLAY
, self
.OnMediaPlay
, self
.mc
)
17 self
.Bind(wx
.media
.EVT_MEDIA_PAUSE
, self
.OnMediaPause
, self
.mc
)
18 self
.Bind(wx
.media
.EVT_MEDIA_STOP
, self
.OnMediaStop
, self
.mc
)
19 self
.Bind(wx
.media
.EVT_MEDIA_FINISHED
, self
.OnMediaFinished
, self
.mc
)
20 self
.Bind(wx
.media
.EVT_MEDIA_LOADED
, self
.OnMediaLoaded
, self
.mc
)
22 selectBtn
= wx
.Button(pnl
, -1, "Select")
23 loadBtn
= wx
.Button(pnl
, -1, "Load")
24 playBtn
= wx
.Button(pnl
, -1, "Play")
25 pauseBtn
= wx
.Button(pnl
, -1, "Pause")
26 stopBtn
= wx
.Button(pnl
, -1, "Stop")
28 self
.Bind(wx
.EVT_BUTTON
, self
.OnBtnSelect
, selectBtn
)
29 self
.Bind(wx
.EVT_BUTTON
, self
.OnBtnLoad
, loadBtn
)
30 self
.Bind(wx
.EVT_BUTTON
, self
.OnBtnPlay
, playBtn
)
31 self
.Bind(wx
.EVT_BUTTON
, self
.OnBtnPause
, pauseBtn
)
32 self
.Bind(wx
.EVT_BUTTON
, self
.OnBtnStop
, stopBtn
)
35 vbox
= wx
.BoxSizer(wx
.VERTICAL
)
36 vbox
.AddF(self
.mc
, wx
.SizerFlags(1).Expand().Border(wx
.ALL
, 5))
37 hbox
= wx
.BoxSizer(wx
.HORIZONTAL
)
38 hbox
.AddF(selectBtn
, wx
.SizerFlags().Border())
39 hbox
.AddF(loadBtn
, wx
.SizerFlags().Border())
40 hbox
.AddF(playBtn
, wx
.SizerFlags().Border())
41 hbox
.AddF(pauseBtn
, wx
.SizerFlags().Border())
42 hbox
.AddF(stopBtn
, wx
.SizerFlags().Border())
47 sizer
.AddF(pnl
, wx
.SizerFlags(1).Expand())
49 wx
.CallLater(200, self
.SetClientSize
, pnl
.GetBestSize())
51 self
.timer
= wx
.Timer(self
)
52 self
.Bind(wx
.EVT_TIMER
, self
.OnShowStatus
)
56 def OnBtnSelect(self
, evt
):
57 name
= wx
.FileSelector("Choose media file")
61 def OnBtnLoad(self
, evt
):
62 print "Loading %s..." % self
.fn
63 print "Load:", self
.mc
.Load(self
.fn
)
65 def OnBtnPlay(self
, evt
):
66 print "Play:", self
.mc
.Play()
68 def OnBtnPause(self
, evt
):
69 print "Pause:", self
.mc
.Pause()
71 def OnBtnStop(self
, evt
):
72 print "Stop:", self
.mc
.Stop()
75 def OnShowStatus(self
, evt
):
76 current
= self
.mc
.Tell()
77 length
= self
.mc
.Length()
79 dl_current
= self
.mc
.GetDownloadProgress()
80 dl_length
= self
.mc
.GetDownloadTotal()
82 cw
,ch
= self
.mc
.GetSize()
83 bw
,bh
= self
.mc
.GetBestSize()
85 vol
= self
.mc
.GetVolume()
87 stateMap
= { wx
.media
.MEDIASTATE_PLAYING
: "Playing",
88 wx
.media
.MEDIASTATE_PAUSED
: "Paused",
89 wx
.media
.MEDIASTATE_STOPPED
: "Stopped", }
90 state
= stateMap
.get(self
.mc
.GetState(), "Other")
92 st
= "Size:%d,%d BSize:%d,%d Pos:%d/%d DL:%d/%d V:%d %s" % (
93 cw
,ch
, bw
,bh
, current
, length
, dl_current
, dl_length
, vol
*100, state
)
95 self
.SetStatusText(st
)
99 def OnMediaPlay(self
, evt
):
102 def OnMediaPause(self
, evt
):
105 def OnMediaStop(self
, evt
):
108 def OnMediaFinished(self
, evt
):
109 print "OnMediaFinished"
111 def OnMediaLoaded(self
, evt
):
112 print "OnMediaLoaded"
116 app
= InspectableApp(False)
117 frm
= TestFrame(None, title
="simple wxMediaCtrl test")