import vlc import wx import random import os.path import time dir = '/home/rarnaoot/Synth/wmv/' FullScreen = 1 UseTimer = 1 SizeConst = 75 class VideoWindow(wx.Window): def __init__( self, parent ): wx.Window.__init__( self, parent, -1 ) self.CurrentFile = 0 self.MaxRange = 10000 self.Files = [] self.FillFiles() def FillFiles( self ): for name in os.listdir(dir): if len(name)>4 and name[-4:]=='.wmv': self.Files.append(dir+name) def Jump ( self ): pos = vlc.Position() playlist = self.video.playlist_get_list() self.MaxRange = os.path.getsize(playlist[0]) / SizeConst t = random.randint(0,self.MaxRange) pos.origin,pos.key,pos.value = vlc.AbsolutePosition,vlc.MediaTime,t self.video.set_media_position(pos) def Next ( self ): self.video.stop() self.video.playlist_clear() for file in self.Files: self.video.playlist_add_item(self.GetRandomFile()) pos = vlc.Position() t = random.randint(0,self.MaxRange) pos.origin,pos.key,pos.value = vlc.AbsolutePosition,vlc.MediaTime,t self.video.start(pos) def GetRandomFile( self ): index = random.randint(0, len(self.Files)-1) return self.Files[index] def play( self ): self.video = vlc.MediaControl(["--verbose","2"]) self.video.set_visual( self.GetHandle() ) for file in self.Files: self.video.playlist_add_item(self.GetRandomFile()) pos = vlc.Position() pos.origin,pos.key,pos.value = vlc.AbsolutePosition,vlc.MediaTime,0 self.video.sound_set_volume(0) self.video.start(pos) class VideoFrame(wx.Frame): def __init__( self ): if (FullScreen): s = wx.DisplaySize() else: s = (800, 600) wx.Frame.__init__( self, None, -1, "VLC playback test", pos=(0,0), size=s) self.sizer = wx.BoxSizer( wx.VERTICAL ) self.vw = VideoWindow( self ) self.sizer.Add( self.vw, 1, wx.EXPAND ) self.SetSizer( self.sizer ) if UseTimer: self.timer = wx.Timer(self, -1) self.timer.Start(25) self.Bind(wx.EVT_TIMER, self.OnTimer) panel = wx.Panel(self, -1) self.count = 0 self.Show(True) panel.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown) panel.SetFocus() self.skip = 1 self.vw.play() def OnTimer(self, event): video = self.vw.video t = time.localtime(time.time()) st = time.strftime("%I:%M:%S", t) if self.count % 50 == 0: self.skip = random.randint(0,2) if self.count == 100: self.count = 0 if self.skip: if self.count == 99: if random.randint(0,3) == 2: self.vw.Next() elif 5 < self.count < 40 or 59 < self.count < 85 : if self.count % 1 == 0: self.vw.Jump() self.count = self.count self.count += 1 def OnKeyDown(self, event): video = self.vw.video keycode = event.GetKeyCode() if keycode == wx.WXK_ESCAPE: self.Close() elif keycode == wx.WXK_TAB: #jump to random position self.vw.Jump() elif keycode == wx.WXK_SPACE: #play random video self.vw.Next() event.Skip() class VideoApp(wx.App): def OnInit(self): if FullScreen: VideoFrame().ShowFullScreen(True) else: VideoFrame().Show() return True app = VideoApp() app.MainLoop()