diff --git a/mediaserver/client.py b/mediaserver/client.py index bef2c04..90bd887 100755 --- a/mediaserver/client.py +++ b/mediaserver/client.py @@ -2,13 +2,11 @@ import dbus import dbus.service import dbus.mainloop.glib -import dbus_smartobject -import event +from . import dbus_smartobject +from . import event -import __main__ import os -import gi from gi.repository import GLib from gi.repository import GObject @@ -18,7 +16,7 @@ class MediaClient(dbus_smartobject.DBusSmartObject): if not quickfolder is None: self._quickfolder = quickfolder else: - self._quickfolder = os.path.dirname(__main__.__file__) + self._quickfolder = os.path.dirname(os.getcwd()) self.Playing = False self.Paused = False @@ -111,7 +109,7 @@ class MediaClient(dbus_smartobject.DBusSmartObject): self.status_position = self.Position() #print "backed up position: {0}".format(self.status_position) - GObject.timeout_add(1000, self.statusticker); + GObject.timeout_add(1000, self.statusticker) #callback function def _onLoading(self,url): @@ -214,15 +212,15 @@ class MediaClient(dbus_smartobject.DBusSmartObject): path = os.path.join(self._quickfolder,file) if not os.path.isfile(path): - path = os.path.join(os.path.dirname(__main__.__file__),file) + path = os.path.join(os.getcwd(),file) try: if duration is None or duration <= 0: self.call("QuickPlay",file) else: self.call("QuickPlayFor",file,duration) - except dbus_smartobject.NoConnectionError as x: - print "Could not call QuickPlay function because of no connection" + except dbus_smartobject.NoConnectionError: + print("Could not call QuickPlay function because of no connection") pass def QuickPlayUrl(self, url, duration = None): @@ -233,25 +231,25 @@ class MediaClient(dbus_smartobject.DBusSmartObject): self.call("QuickPlayUrl",url) else: self.call("QuickPlayUrlFor",url,duration) - except dbus_smartobject.NoConnectionError as x: - print "Could not call QuickPlayUrl function because of no connection" + except dbus_smartobject.NoConnectionError: + print("Could not call QuickPlayUrl function because of no connection") pass def QuickLoop(self, file): """ Directly play back a local file """ path = file - # check if the file exists, if not, try to find it in the base folder for quickplay or else as a subfolder of the __main__ folder + # check if the file exists, if not, try to find it in the base folder for quickplay or else as a subfolder of the __main__ folder if not os.path.isfile(path): path = os.path.join(self._quickfolder,file) if not os.path.isfile(path): - path = os.path.join(os.path.dirname(__main__.__file__),file) + path = os.path.join(os.getcwd(),file) try: self.call("QuickLoop",file) - except dbus_smartobject.NoConnectionError as x: - print "Could not call QuickPlay function because of no connection" + except dbus_smartobject.NoConnectionError: + print("Could not call QuickPlay function because of no connection") pass def QuickLoopUrl(self, url): @@ -259,8 +257,8 @@ class MediaClient(dbus_smartobject.DBusSmartObject): """ try: self.call("QuickLoopUrl",url) - except dbus_smartobject.NoConnectionError as x: - print "Could not call QuickPlayUrl function because of no connection" + except dbus_smartobject.NoConnectionError: + print("Could not call QuickPlayUrl function because of no connection") pass def LoadFile(self, file): @@ -268,8 +266,8 @@ class MediaClient(dbus_smartobject.DBusSmartObject): """ try: self.call("LoadFile",file) - except dbus_smartobject.NoConnectionError as x: - print "Could not call LoadFile because of no connection" + except dbus_smartobject.NoConnectionError: + print("Could not call LoadFile because of no connection") pass def LoadUrl(self, url): @@ -277,8 +275,8 @@ class MediaClient(dbus_smartobject.DBusSmartObject): """ try: self.call("LoadUrl",url) - except dbus_smartobject.NoConnectionError as x: - print "Could not call LoadUrl because of no connection" + except dbus_smartobject.NoConnectionError: + print("Could not call LoadUrl because of no connection") pass def PlayFor(self, duration): @@ -286,8 +284,8 @@ class MediaClient(dbus_smartobject.DBusSmartObject): """ try: self.call("PlayFor",duration) - except dbus_smartobject.NoConnectionError as x: - print "Could not call PlayFor because of no connection" + except dbus_smartobject.NoConnectionError: + print("Could not call PlayFor because of no connection") pass def Play(self): @@ -295,8 +293,8 @@ class MediaClient(dbus_smartobject.DBusSmartObject): """ try: self.call("Play") - except dbus_smartobject.NoConnectionError as x: - print "Could not call Play because of no connection" + except dbus_smartobject.NoConnectionError: + print("Could not call Play because of no connection") pass def Loop(self): @@ -304,8 +302,8 @@ class MediaClient(dbus_smartobject.DBusSmartObject): """ try: self.call("Loop") - except dbus_smartobject.NoConnectionError as x: - print "Could not call Loop because of no connection" + except dbus_smartobject.NoConnectionError: + print("Could not call Loop because of no connection") pass def Pause(self): @@ -313,8 +311,8 @@ class MediaClient(dbus_smartobject.DBusSmartObject): """ try: self.call("Pause") - except dbus_smartobject.NoConnectionError as x: - print "Could not call Pause because of no connection" + except dbus_smartobject.NoConnectionError: + print("Could not call Pause because of no connection") pass def Stop(self): @@ -322,8 +320,8 @@ class MediaClient(dbus_smartobject.DBusSmartObject): """ try: self.call("Stop") - except dbus_smartobject.NoConnectionError as x: - print "Could not call Stop because of no connection" + except dbus_smartobject.NoConnectionError: + print("Could not call Stop because of no connection") pass def Length(self): @@ -331,8 +329,8 @@ class MediaClient(dbus_smartobject.DBusSmartObject): """ try: return self.call("Length") - except dbus_smartobject.NoConnectionError as x: - print "Could not call Length because of no connection" + except dbus_smartobject.NoConnectionError: + print("Could not call Length because of no connection") return 0 def Position(self): @@ -340,8 +338,8 @@ class MediaClient(dbus_smartobject.DBusSmartObject): """ try: return self.call("Position") - except dbus_smartobject.NoConnectionError as x: - print "Could not call Position because of no connection" + except dbus_smartobject.NoConnectionError: + print("Could not call Position because of no connection") return 0 def Seek(self,position): @@ -351,7 +349,7 @@ class MediaClient(dbus_smartobject.DBusSmartObject): self.call("Seek",position) self.status_position = position - except dbus_smartobject.NoConnectionError as x: - print "Could not call because of no connection" + except dbus_smartobject.NoConnectionError: + print("Could not call because of no connection") pass diff --git a/stdeb.cfg b/stdeb.cfg index 4c4cf43..a894080 100755 --- a/stdeb.cfg +++ b/stdeb.cfg @@ -1,6 +1,6 @@ [DEFAULT] -Depends: python-dbus, python-gi, gir1.2-gstreamer-1.0, gir1.2-gst-plugins-base-1.0, gstreamer1.0-plugins-good, gstreamer1.0-plugins-ugly, gstreamer1.0-plugins-bad, gstreamer1.0-alsa, gstreamer1.0-omx, gstreamer1.0-libav +Depends: python3-dbus, python3-gi, gir1.2-gstreamer-1.0, gstreamer1.0-gtk3, gir1.2-gst-plugins-base-1.0, gstreamer1.0-plugins-good, gstreamer1.0-plugins-ugly, gstreamer1.0-plugins-bad, gstreamer1.0-alsa, gstreamer1.0-x XS-Python-Version: >= 2.6 Section: sound Package: mediaserver diff --git a/test_client.py b/test_client.py index 6c4ae64..986c7e2 100755 --- a/test_client.py +++ b/test_client.py @@ -29,11 +29,18 @@ class TestController: GObject.timeout_add(10, self.tick) + GObject.timeout_add(90000, self.getPosition) + def tick(self): self.player.QuickPlay(sys.argv[1]) #GObject.timeout_add(3000, self.reboot) pass + def getPosition(self): + pos = self.player.Position() + print("Position:") + print(pos) + def onStarting(self): pass