Michele Orrù avatar Michele Orrù committed 114d6e5

Timeslider Updated.

Comments (0)

Files changed (1)

player-example.py

 
         # The second panel holds controls
         ctrlpanel = wx.Panel(self, -1 )
-        self.timeslider = wx.Slider(ctrlpanel, -1, 0, 0, 1000, style=wx.SL_AUTOTICKS)
+        self.timeslider = wx.Slider(ctrlpanel, -1, 0, 0, 1000)
+        self.timeslider.SetRange(0, 1000)
         pause = wx.BitmapButton(ctrlpanel, -1,
                                 wx.Bitmap(self.ICONSPATH+"pause.png"))
         play  = wx.BitmapButton(ctrlpanel, -1,
         # VLC player controls
         self.player = None
         self.play = False
-        self.mute = True
+        self.timer = wx.Timer(self)
+        self.Bind(wx.EVT_TIMER, self.OnSeek, self.timer)
 
     def OnExit(self, evt):
         """
         # if a file is already running, then stop it.
         if self.player:
             self.player.stop()
+            self.timer.Stop()
 
         # Create a file dialog opened in the current home directory, where
         # you can display all kind of files, having as title "Choose a file".
                 title = filename
             self.SetTitle("%s - wxVLCplayer" % title)
 
+
+            # set the wiindow system where to render VLC's video output
+            self.player.set_xwindow(self.videopanel.GetHandle())
             self.OnPlay(None)
 
-            # set the time slider range
-            length = self.player.get_length()
-            print length
-            self.timeslider.SetRange(0, length)
             # set the volume slider to the current volume
             self.volslider.SetValue(self.player.audio_get_volume() // 2)
 
         if not self.player:
             self.OnOpen(None)
         else:
-                self.player.play()
-
-        # set the wiindow system where to render VLC's video output
-        self.player.set_xwindow(self.videopanel.GetHandle())
+            if self.player.play() == -1:
+                self.errorDialog("Unable to play.")
+            self.timer.Start()
 
     def OnPause(self, evt):
         """
         Pause the player.
         """
         if self.player:
-            print self.player.get_length()
             self.player.pause()
+        else:
+            self.errorDialog("No movie loaded.")
 
     def OnSeek(self, evt):
         """
-        Seek for a specified time in player slider.
+        Update the time slider according to the current movie time.
         """
-        time = self.player.get_time()
+        # since the self.player.get_length can change while playing,
+        # re-set the timeslider to the correct range.
+        length = self.player.get_length()
+        self.timeslider.SetRange(-1, length)
+
+        if self.player:
+            time = self.player.get_time()
+        else:
+            time = 0
         self.timeslider.SetValue(time)
 
     def OnToggleVolume(self, evt):
         """
         Mute/Unmute according to the audio button.
         """
-        self.player.audio_set_mute(self.mute)
+        is_mute = self.player.audio_get_mute()
+
+        self.player.audio_set_mute(not is_mute)
         # update the volume slider
-        if self.mute:
+        if is_mute:
             self.volslider.SetValue(0)
         else:
             # since vlc volume range is in [0, 200],
             self.volslider.SetValue(self.player.audio_get_volume() // 2)
 
 
-        # finally switch self.mute attribute
-        self.mute = not self.mute
-
     def OnSetVolume(self, evt):
         """
         Set the volume according to the volume sider.
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.