]> git.parisson.com Git - piplayer.git/commitdiff
init
authorGuillaume Pellerin <yomguy@parisson.com>
Mon, 22 Jul 2013 21:59:02 +0000 (23:59 +0200)
committerGuillaume Pellerin <yomguy@parisson.com>
Mon, 22 Jul 2013 21:59:02 +0000 (23:59 +0200)
audio_player_osc.py [new file with mode: 0644]
osc_play.py [new file with mode: 0644]
osc_stop.py [new file with mode: 0644]

diff --git a/audio_player_osc.py b/audio_player_osc.py
new file mode 100644 (file)
index 0000000..609882c
--- /dev/null
@@ -0,0 +1,57 @@
+
+import gobject
+gobject.threads_init()
+import pygst
+pygst.require("0.10")
+import gst
+from threading import Thread
+import sys
+import liblo
+
+class OSCController(Thread):
+
+    def __init__(self, port):
+        Thread.__init__(self)
+        import liblo
+        self.port = port
+        try:
+            self.server = liblo.Server(self.port)
+        except liblo.ServerError, err:
+            print str(err)
+
+    def run(self):
+        while True:
+            self.server.recv(100)
+
+            
+class AudioPlayer(Thread):
+    
+    def __init__(self, uri):
+        Thread.__init__(self)
+        self.uri = uri
+        self.controller = OSCController(12345)
+        self.controller.server.add_method('/play', 'i', self.play_stop_cb)
+        self.controller.start()
+        
+        self.mainloop = gobject.MainLoop()
+        self.player = gst.element_factory_make("playbin", "player")
+        self.player.set_property('uri', self.uri)
+        
+    def play_stop_cb(self, path, value):
+        value = value[0]
+        if value:
+            print 'play'
+            self.player.set_state(gst.STATE_NULL)
+            self.player.set_state(gst.STATE_PLAYING)
+        else:
+            print 'stop'
+            self.player.set_state(gst.STATE_NULL)
+            
+    def run(self):
+        self.mainloop.run()
+    
+if __name__ == '__main__':
+    path = sys.argv[-1]
+    player = AudioPlayer(path)
+    player.start()
+    
diff --git a/osc_play.py b/osc_play.py
new file mode 100644 (file)
index 0000000..76e4922
--- /dev/null
@@ -0,0 +1,14 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import liblo, sys
+
+# send all messages to port 1234 on the local machine
+try:
+    target = liblo.Address(12345)
+except liblo.AddressError, err:
+    print str(err)
+    sys.exit()
+
+# send message "/foo/message1" with int, float and string arguments
+liblo.send(target, "/play", 1)
diff --git a/osc_stop.py b/osc_stop.py
new file mode 100644 (file)
index 0000000..cce3314
--- /dev/null
@@ -0,0 +1,14 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import liblo, sys
+
+# send all messages to port 1234 on the local machine
+try:
+    target = liblo.Address(12345)
+except liblo.AddressError, err:
+    print str(err)
+    sys.exit()
+
+# send message "/foo/message1" with int, float and string arguments
+liblo.send(target, "/play", 0)