Improved play function. Now it should play only an audio at the same time

This commit is contained in:
Manuel Cortez 2016-02-19 17:30:11 -06:00
parent 4fd4bd07a4
commit 4acf363f3e
2 changed files with 14 additions and 4 deletions

View File

@ -17,13 +17,18 @@ class audioPlayer(object):
self.is_playing = False self.is_playing = False
self.stream = None self.stream = None
self.vol = 100 self.vol = 100
self.is_working = False
def play(self, url): def play(self, url):
if self.stream != None and self.stream.is_playing == True: if self.stream != None and self.stream.is_playing == True:
self.stream.stop() self.stream.stop()
self.stream = URLStream(url=url) # Make sure that there are no other sounds trying to be played.
self.stream.volume = self.vol/100.0 if self.is_working == False:
self.stream.play() self.is_working = True
self.stream = URLStream(url=url)
self.stream.volume = self.vol/100.0
self.stream.play()
self.is_working = False
def stop(self): def stop(self):
if self.stream != None and self.stream.is_playing == True: if self.stream != None and self.stream.is_playing == True:

View File

@ -93,6 +93,7 @@ def compose_status(status, session):
return [user, message, created_at] return [user, message, created_at]
def compose_audio(audio, session): def compose_audio(audio, session):
if audio == False: return [_(u"Audio removed from library"), "", ""]
return [audio["title"], audio["artist"], utils.seconds_to_string(audio["duration"])] return [audio["title"], audio["artist"], utils.seconds_to_string(audio["duration"])]
class vkSession(object): class vkSession(object):
@ -160,6 +161,7 @@ class vkSession(object):
self.authorise() self.authorise()
else: else:
self.authorise() self.authorise()
self.get_my_data()
def authorise(self): def authorise(self):
self.vk.login(self.settings["vk"]["user"], self.settings["vk"]["password"]) self.vk.login(self.settings["vk"]["user"], self.settings["vk"]["password"])
@ -235,3 +237,6 @@ class vkSession(object):
self.db["users"][i["uid"]] = u"{0} {1}".format(i["first_name"], i["last_name"]) self.db["users"][i["uid"]] = u"{0} {1}".format(i["first_name"], i["last_name"])
for i in data["groups"]: for i in data["groups"]:
self.db["groups"][i["gid"]] = i["name"] self.db["groups"][i["gid"]] = i["name"]
def get_my_data(self):
self.user_id = self.vk.client.users.get(fields="uid")[0]["uid"]