]> git.parisson.com Git - piplayer.git/commitdiff
separate play & stop channels
authorGuillaume Pellerin <yomguy@parisson.com>
Tue, 23 Jul 2013 02:53:58 +0000 (04:53 +0200)
committerGuillaume Pellerin <yomguy@parisson.com>
Tue, 23 Jul 2013 02:53:58 +0000 (04:53 +0200)
piplayer.py

index 5b0385c7c31eb5da4a3ff48f0636924c279b13af..8591c36f13aab766d707f6bd22a2f2db8cd262c9 100644 (file)
@@ -71,6 +71,7 @@ class AudioPlayer(object):
     
     osc_port = 12345
     gpio_channel_play = 22
+    gpio_channel_stop = 23
     playing = False
     
     def __init__(self, uri):    
@@ -79,11 +80,13 @@ class AudioPlayer(object):
         # OSC controller
         self.osc_controller = OSCController(self.osc_port)
         self.osc_controller.add_method('/play', 'i', self.osc_play_stop)
+        self.osc_controller.add_method('/stop', 'i', self.osc_play_stop)
         self.osc_controller.start()
  
         # GPIO controller
         self.gpio_controller = GPIOController()
         self.gpio_controller.add_channel_callback(self.gpio_channel_play, self.gpio_play)
+        self.gpio_controller.add_channel_callback(self.gpio_channel_stop, self.gpio_stop)
         self.gpio_controller.start()
         
         # The pipeline
@@ -146,27 +149,30 @@ class AudioPlayer(object):
         print 'on_error:', error[1]
         self.mainloop.quit()
  
-    def osc_play_stop(self, path, value):
-        value = value[0]
-        if value and not self.playing:
-            #print 'play'
+    def play(self):
+        if not self.playing:
             self.pipeline.set_state(gst.STATE_NULL)
             self.pipeline.set_state(gst.STATE_PLAYING)
             self.playing = True
-        else:
+    
+    def stop(self):
+        if self.playing:
             self.pipeline.set_state(gst.STATE_NULL)
             self.playing = False
 
-    def gpio_play(self, value):
-        if not self.playing:
-            #print 'play'
-            self.pipeline.set_state(gst.STATE_NULL)
-            self.pipeline.set_state(gst.STATE_PLAYING)
-            self.playing = True
+    def osc_play_stop(self, path, value):
+        value = value[0]
+        if value and not self.playing:
+            self.play()
         else:
-            self.pipeline.set_state(gst.STATE_NULL)
-            self.playing = False
-        
+            self.stop()
+            
+    def gpio_play(self, channel):
+        self.play()
+
+    def gpio_stop(self, channel):
+        self.stop()
+            
     def update_uri(uri):
         self.uri = uri
         self.srcdec.set_property('uri', self.uri)