# -*- coding: utf-8 -*-
import wx, wx.media
import time
class TestPanel(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None)
self.testMedia = wx.media.MediaCtrl(self,
szBackend=wx.media.MEDIABACKEND_WMP10,
style=wx.SIMPLE_BORDER,)
self.MOVE = ('6.mpg', '7.wmv','1.avi','4.jpg')
self.testMedia.Load(self.MOVE[0])
self.testMedia.Bind(wx.media.EVT_MEDIA_LOADED, self.play, self.testMedia)
self.testMedia.Bind(wx.media.EVT_MEDIA_STATECHANGED, self.play2, self.testMedia)
def play(self, e):
self.testMedia.GetBestSize()
self.testMedia.Play()
def play2(self, e):
if self.testMedia.GetState() == wx.media.MEDIASTATE_STOPPED:
for i in range(len(self.MOVE)):
if i == 1:
self.testMedia.Load(self.MOVE[1])
elif i == 2:
self.testMedia.Load(self.MOVE[2])
elif i == 3:
self.testMedia.Load(self.MOVE[3])
if __name__ == '__main__':
app = wx.App()
Fream = TestPanel()
Fream.Show(True)
app.MainLoop()
help me plz how next self.MOVE[0] -> [1] -> [2] -> [3] -> [0] .... Loop play I’m at a loss what to do next... and Where can see wx.media tutorial and exmple code??
You shouldn't use wx.media.EVT_MEDIA_STATECHANGED it could change for other reasons than the media has finished. Use wx.media.EVT_MEDIA_FINISHED instead.
You can loop using a simple counter.
On state Finished perform the next Load with the index and the code should work.
I note that the last item you load is a .jpg. Not sure how that is meant to "finish"!
# -*- coding: utf-8 -*-
import wx, wx.media
import time
class TestPanel(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None)
self.testMedia = wx.media.MediaCtrl(self,
szBackend=wx.media.MEDIABACKEND_WMP10,
# szBackend=wx.media.MEDIABACKEND_GSTREAMER,
style=wx.SIMPLE_BORDER,)
self.MOVE = ('6.mpg', '7.wmv','1.avi','4.jpg')
# self.MOVE = ('V1.mp4', 'V2.mp4','V3.mp4','V4.mp4')
self.Mrange = 0
self.testMedia.Bind(wx.media.EVT_MEDIA_LOADED, self.play, self.testMedia)
self.testMedia.Bind(wx.media.EVT_MEDIA_FINISHED, self.play2, self.testMedia)
self.testMedia.Load(self.MOVE[self.Mrange])
def play(self, e):
print "Playing:",self.MOVE[self.Mrange]
self.testMedia.Play()
def play2(self, e):
self.testMedia.Stop()
self.Mrange += 1
print self.Mrange
if self.Mrange > len(self.MOVE) -1:
self.Mrange = 0
self.testMedia.Load(self.MOVE[self.Mrange])
if __name__ == '__main__':
app = wx.App()
Fream = TestPanel()
Fream.Show(True)
app.MainLoop()