# -*- coding: utf-8 -*- import wx import wx.media class MainPanel(wx.Panel): def __init__(self, parent): wx.Panel.__init__(self,parent) self.index = 0 self.song_list = [ "c:/Windows/Media/ring01.wav", "c:/Windows/Media/tada.wav", "c:/Windows/Media/Windows Print complete.wav" ] bz = wx.BoxSizer( wx.VERTICAL ) self.media = wx.media.MediaCtrl( self, -1, szBackend=wx.media.MEDIABACKEND_WMP10 ) self.media.Bind( wx.media.EVT_MEDIA_FINISHED, self.onNext ) self.media.Bind( wx.media.EVT_MEDIA_LOADED, self.onLoad ) button = wx.Button(self, -1, 'play') button.Bind(wx.EVT_BUTTON, self.onplay) bz.Add( button ) button2 = wx.Button(self, -1, 'rewind') button2.Bind(wx.EVT_BUTTON, self.onRewind) bz.Add( button2 ) self.SetSizer( bz ) self.Fit() def onplay(self, evt): print "onplay" self.media.Load( self.song_list[0] ) evt.Skip() def onLoad(self, evt): print "onLoad" self.media.Play() evt.Skip() def onNext( self, evt ): print "onNext" self.index = (self.index + 1) % len(self.song_list) print( self.media.Load( self.song_list[self.index] ) ) evt.Skip() def onRewind( self, evt ): self.media.Stop() self.index = 0 self.onplay( evt ) class MainFrame(wx.Frame): def __init__(self,): wx.Frame.__init__(self, None, title="test") self.panel = MainPanel(self) self.Show() app = wx.App(0) frame = MainFrame() app.MainLoop()