Moved audio playback infrastructure to pubsub events

This commit is contained in:
Manuel Cortez 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: if post == None:
return return
if "type" in post and post["type"] == "audio": 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 return True
def open_person_profile(self, *args, **kwargs): def open_person_profile(self, *args, **kwargs):
@ -601,7 +601,7 @@ class audioBuffer(feedBuffer):
selected = self.tab.list.get_selected() selected = self.tab.list.get_selected()
if selected == -1: if selected == -1:
selected = 0 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 return True
def play_next(self, *args, **kwargs): def play_next(self, *args, **kwargs):
@ -637,7 +637,7 @@ class audioBuffer(feedBuffer):
if self.name not in self.session.db: if self.name not in self.session.db:
return return
audios = [i for i in self.session.db[self.name]["items"][selected:]] 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 return True
def remove_buffer(self, mandatory=False): def remove_buffer(self, mandatory=False):

View File

@ -283,8 +283,6 @@ class Controller(object):
log.debug("Connecting events to responses...") log.debug("Connecting events to responses...")
pub.subscribe(self.in_post, "posted") pub.subscribe(self.in_post, "posted")
pub.subscribe(self.download, "download-file") 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.view_post, "open-post")
pub.subscribe(self.update_status_bar, "update-status-bar") pub.subscribe(self.update_status_bar, "update-status-bar")
pub.subscribe(self.chat_from_id, "new-chat") pub.subscribe(self.chat_from_id, "new-chat")
@ -303,9 +301,7 @@ class Controller(object):
log.debug("Disconnecting some events...") log.debug("Disconnecting some events...")
pub.unsubscribe(self.in_post, "posted") pub.unsubscribe(self.in_post, "posted")
pub.unsubscribe(self.download, "download-file") pub.unsubscribe(self.download, "download-file")
pub.unsubscribe(self.play_audio, "play-audio")
pub.unsubscribe(self.authorisation_failed, "authorisation-failed") pub.unsubscribe(self.authorisation_failed, "authorisation-failed")
pub.unsubscribe(self.play_audios, "play-audios")
pub.unsubscribe(self.view_post, "open-post") pub.unsubscribe(self.view_post, "open-post")
pub.unsubscribe(self.update_status_bar, "update-status-bar") pub.unsubscribe(self.update_status_bar, "update-status-bar")
pub.unsubscribe(self.user_online, "user-online") pub.unsubscribe(self.user_online, "user-online")
@ -331,23 +327,6 @@ class Controller(object):
log.debug("downloading %s URL to %s filename" % (url, filename,)) log.debug("downloading %s URL to %s filename" % (url, filename,))
call_threaded(utils.download_file, url, filename, self.window) 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_): def view_post(self, post_object, controller_):
""" Display the passed post in the passed post presenter. """ 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. @ 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.

View File

@ -46,7 +46,7 @@ class audioPlayer(object):
# Set timeout connection to 30 seconds. # Set timeout connection to 30 seconds.
bassconfig["net_timeout"] = 30000 bassconfig["net_timeout"] = 30000
pub.subscribe(self.play, "play") 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.pause, "pause")
pub.subscribe(self.stop, "stop") pub.subscribe(self.stop, "stop")
pub.subscribe(self.play_next, "play_next") 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. @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. @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.""" @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: if self.stream != None and self.stream.is_playing == True:
try: try:
self.stream.stop() self.stream.stop()

View File

@ -763,7 +763,7 @@ class displayAudioPresenter(base.basePresenter):
def play(self, audio_index): def play(self, audio_index):
post = self.post[audio_index] post = self.post[audio_index]
pub.sendMessage("play-audio", audio_object=post) pub.sendMessage("play", object=post)
def load_audios(self): def load_audios(self):
audios = [] audios = []