From a0d43ebe0ecad002e1ee78ba1ad2c9bc6b302056 Mon Sep 17 00:00:00 2001 From: Manuel Cortez Date: Thu, 11 Apr 2019 17:15:45 -0500 Subject: [PATCH] Moved audio playback infrastructure to pubsub events --- src/controller/buffers.py | 6 +++--- src/controller/mainController.py | 21 --------------------- src/presenters/player.py | 5 ++++- src/presenters/postDisplayer.py | 2 +- 4 files changed, 8 insertions(+), 26 deletions(-) diff --git a/src/controller/buffers.py b/src/controller/buffers.py index 374a007..d94ad25 100644 --- a/src/controller/buffers.py +++ b/src/controller/buffers.py @@ -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): diff --git a/src/controller/mainController.py b/src/controller/mainController.py index f511279..bf80e36 100644 --- a/src/controller/mainController.py +++ b/src/controller/mainController.py @@ -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. diff --git a/src/presenters/player.py b/src/presenters/player.py index 8a4c332..19a95b8 100644 --- a/src/presenters/player.py +++ b/src/presenters/player.py @@ -46,7 +46,7 @@ class audioPlayer(object): # Set timeout connection to 30 seconds. bassconfig["net_timeout"] = 30000 pub.subscribe(self.play, "play") - pub.subscribe(self.play_all, "play_all") + pub.subscribe(self.play_all, "play-all") pub.subscribe(self.pause, "pause") pub.subscribe(self.stop, "stop") pub.subscribe(self.play_next, "play_next") @@ -57,6 +57,9 @@ class audioPlayer(object): @object dict: typically an audio object as returned by VK, with a "url" component which must be a valid URL to a media file. @set_info bool: If true, will set information about the currently playing audio in the application status bar. @fresh bool: If True, will remove everything playing in the queue and start this file only. otherwise it will play the new file but not remove the current queue.""" + if "url" in object and object["url"] =="": + pub.sendMessage("notify", message=_("This file could not be played because it is not allowed in your country")) + return if self.stream != None and self.stream.is_playing == True: try: self.stream.stop() diff --git a/src/presenters/postDisplayer.py b/src/presenters/postDisplayer.py index 01c00e9..4185136 100644 --- a/src/presenters/postDisplayer.py +++ b/src/presenters/postDisplayer.py @@ -763,7 +763,7 @@ class displayAudioPresenter(base.basePresenter): def play(self, audio_index): post = self.post[audio_index] - pub.sendMessage("play-audio", audio_object=post) + pub.sendMessage("play", object=post) def load_audios(self): audios = []