Moved audio playback infrastructure to pubsub events

This commit is contained in:
2019-04-11 17:15:45 -05:00
parent 6d80dce66d
commit a0d43ebe0e
4 changed files with 8 additions and 26 deletions

View File

@@ -328,7 +328,7 @@ class baseBuffer(object):
if post == None:
return
if "type" in post and post["type"] == "audio":
pub.sendMessage("play-audio", object=post["audio"]["items"][0])
pub.sendMessage("play", object=post["audio"]["items"][0])
return True
def open_person_profile(self, *args, **kwargs):
@@ -601,7 +601,7 @@ class audioBuffer(feedBuffer):
selected = self.tab.list.get_selected()
if selected == -1:
selected = 0
pub.sendMessage("play-audio", object=self.session.db[self.name]["items"][selected])
pub.sendMessage("play", object=self.session.db[self.name]["items"][selected])
return True
def play_next(self, *args, **kwargs):
@@ -637,7 +637,7 @@ class audioBuffer(feedBuffer):
if self.name not in self.session.db:
return
audios = [i for i in self.session.db[self.name]["items"][selected:]]
pub.sendMessage("play-audios", audios=audios)
pub.sendMessage("play-all", list_of_songs=audios)
return True
def remove_buffer(self, mandatory=False):

View File

@@ -283,8 +283,6 @@ class Controller(object):
log.debug("Connecting events to responses...")
pub.subscribe(self.in_post, "posted")
pub.subscribe(self.download, "download-file")
pub.subscribe(self.play_audio, "play-audio")
pub.subscribe(self.play_audios, "play-audios")
pub.subscribe(self.view_post, "open-post")
pub.subscribe(self.update_status_bar, "update-status-bar")
pub.subscribe(self.chat_from_id, "new-chat")
@@ -303,9 +301,7 @@ class Controller(object):
log.debug("Disconnecting some events...")
pub.unsubscribe(self.in_post, "posted")
pub.unsubscribe(self.download, "download-file")
pub.unsubscribe(self.play_audio, "play-audio")
pub.unsubscribe(self.authorisation_failed, "authorisation-failed")
pub.unsubscribe(self.play_audios, "play-audios")
pub.unsubscribe(self.view_post, "open-post")
pub.unsubscribe(self.update_status_bar, "update-status-bar")
pub.unsubscribe(self.user_online, "user-online")
@@ -331,23 +327,6 @@ class Controller(object):
log.debug("downloading %s URL to %s filename" % (url, filename,))
call_threaded(utils.download_file, url, filename, self.window)
def play_audio(self, audio_object):
""" Play an audio by using the local media player object.
@ audio_object dict: An audio representation returned by the VK API.
"""
# Restricted audios don't include an URL paramether.
# Restriction can be due to licensed content to unauthorized countries.
if "url" in audio_object and audio_object["url"] =="":
self.notify(message=_("This file could not be played because it is not allowed in your country"))
return
pub.sendMessage("play", object=audio_object, fresh=True)
def play_audios(self, audios):
""" Play all audios passed in alist, putting the audio in a queue of the media player.
@audios list: A list of Vk audio objects.
"""
pub.sendMessage("play_all", list_of_songs=audios, shuffle=self.window.player_shuffle.IsChecked())
def view_post(self, post_object, controller_):
""" Display the passed post in the passed post presenter.
@ post_object dict: A post representation returned by the VK api. The fields present in this dict are different depending on the presenter used to render it.