Commits

Michele Orrù  committed 85f5a32

All controls -1 done

  • Participants
  • Parent commits 3f30680

Comments (0)

Files changed (1)

File player-example.py

 Date: 23-11-2010
 """
 
+from __future__ import division
+
 # import external libraries
 import wx # 2.8
 import vlc
 
         # The second panel holds controls
         ctrlpanel = wx.Panel(self, -1 )
-        self.timeslider = wx.Slider(ctrlpanel, -1, 0, 0, 1000)
+        self.timeslider = wx.Slider(ctrlpanel, -1, 0, 0, 1000, style=wx.SL_AUTOTICKS)
         pause = wx.BitmapButton(ctrlpanel, -1,
                                 wx.Bitmap(self.ICONSPATH+"pause.png"))
         play  = wx.BitmapButton(ctrlpanel, -1,
                                 wx.Bitmap(self.ICONSPATH+"play.png"))
         volume = wx.BitmapButton(ctrlpanel, -1,
                                  wx.Bitmap(self.ICONSPATH+'volume.png'))
-        self.volslider = wx.Slider(ctrlpanel, -1, 0, 0, 100, size=(120, -1))
+        self.volslider = wx.Slider(ctrlpanel, -1, 0, 0, 100, size=(100, -1))
         # bind controls to events
         self.Bind(wx.EVT_BUTTON, self.OnPlay, play)
         self.Bind(wx.EVT_BUTTON, self.OnPause, pause)
         Pop up a new dialow window to choose a file, then play the selected
         file.
         """
+        # if a file is already running, then stop it.
+        if self.player:
+            self.player.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".
         dlg = wx.FileDialog(self, "Choose a file", os.environ["HOME"], "",
             self.SetTitle("%s - wxVLCplayer" % title)
 
             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)
+
         dlg.Destroy()
 
     def OnPlay(self, evt):
         Pause the player.
         """
         if self.player:
+            print self.player.get_length()
             self.player.pause()
 
     def OnSeek(self, evt):
         """
         Seek for a specified time in player slider.
         """
-        pass
+        time = self.player.get_time()
+        self.timeslider.SetValue(time)
 
     def OnToggleVolume(self, evt):
         """
         Mute/Unmute according to the audio button.
         """
         self.player.audio_set_mute(self.mute)
+        # update the volume slider
+        if self.mute:
+            self.volslider.SetValue(0)
+        else:
+            # since vlc volume range is in [0, 200],
+            # and our volume slider has range [0, 100], just divide by 2.
+            self.volslider.SetValue(self.player.audio_get_volume() // 2)
+
 
         # finally switch self.mute attribute
         self.mute = not self.mute
         """
         Set the volume according to the volume sider.
         """
-        volume = self.vslider.GetValue()
+        volume = self.volslider.GetValue() * 2
         # vlc.MediaPlayer.audio_set_volume returns 0 if success, -1 otherwise
         if self.player.audio_set_volume(volume) == -1:
             self.errorDialog("Failed to set volume")