Damián Nohales avatar Damián Nohales committed 27a75c4

Add a pause button

Comments (0)

Files changed (2)

data/main_window.ui

     <property name="pixel_size">23</property>
     <property name="icon_name">media-skip-forward</property>
   </object>
+  <object class="GtkImage" id="image_playlist_pause">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="pixel_size">22</property>
+    <property name="icon_name">media-playback-pause</property>
+    <property name="icon-size">1</property>
+  </object>
   <object class="GtkImage" id="image_playlist_repeat">
     <property name="visible">True</property>
     <property name="can_focus">False</property>
                       </packing>
                     </child>
                     <child>
+                      <object class="GtkToggleButton" id="button_pause">
+                        <property name="width_request">40</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">True</property>
+                        <property name="use_action_appearance">False</property>
+                        <property name="image">image_playlist_pause</property>
+                        <signal name="clicked" handler="on_pause_toggled" swapped="no"/>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                        <property name="position">2</property>
+                      </packing>
+                    </child>
+                    <child>
                       <object class="GtkButton" id="button_play_next">
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
                       <packing>
                         <property name="expand">False</property>
                         <property name="fill">True</property>
-                        <property name="position">2</property>
+                        <property name="position">3</property>
                       </packing>
                     </child>
                     <child>
                       <packing>
                         <property name="expand">False</property>
                         <property name="fill">True</property>
-                        <property name="position">3</property>
+                        <property name="position">4</property>
                       </packing>
                     </child>
                     <child>
                       <packing>
                         <property name="expand">True</property>
                         <property name="fill">True</property>
-                        <property name="position">4</property>
+                        <property name="position">5</property>
                       </packing>
                     </child>
                     <child>
                         <property name="expand">False</property>
                         <property name="fill">True</property>
                         <property name="padding">2</property>
-                        <property name="position">5</property>
+                        <property name="position">6</property>
                       </packing>
                     </child>
                   </object>
         self.hbox_filter = builder.get_object('hbox_filter')
 
         self.button_play = builder.get_object('button_play')
+        self.button_pause = builder.get_object('button_pause')
         self.widget_image_play = builder.get_object('widget_image_play')
         self.widget_image_stop = builder.get_object('widget_image_stop')
         self.widget_image_buffering = gtk.Image()
         return self.playlist.get_song_iter(self.get_playing_song())
 
     def on_player_message(self, bus, message):
-        if message.type == gst.MESSAGE_BUFFERING:
-            if message.parse_buffering() >= 100:
+        if message.type == gst.MESSAGE_BUFFERING or message.type == gst.MESSAGE_ASYNC_DONE:
+            if message.parse_buffering() >= 100 or message.type == gst.MESSAGE_ASYNC_DONE:
                 self.is_buffering = False
                 self.button_play.set_image(self.widget_image_stop)
+                self.button_pause.set_sensitive(True)
             elif not self.is_buffering:
                 self.button_play.set_image(self.widget_image_buffering)
                 self.is_buffering = True
         self.update_trackinfo()
         self.label_player_time.set_text("00:00 / 00:00")
         self.player.set_state(gst.STATE_NULL)
+        self.button_pause.set_sensitive(False)
+        self.button_pause.set_active(False)
 
         if song != None:
             self.is_buffering = True
     def play_first_song(self):
         if len(self.playlist) > 0:
             self.set_playing_song(self.playlist.get_song(0))
-
+    
+    def on_pause_toggled(self, widget):
+        if self.button_pause.get_active() == True:
+            self.player.set_state(gst.STATE_PAUSED)
+        else:
+            self.player.set_state(gst.STATE_PLAYING)
+    
     def on_play_selected(self, widget, data = None, row = None):
         """
         Starts the play thread
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.