......@@ -328,7 +328,7 @@ class baseBuffer(object):
if post == None:
if "type" in post and post["type"] == "audio":
pub.sendMessage("play-audio", audio_object=post["audio"]["items"][0])
pub.sendMessage("play", object=post["audio"]["items"][0])
return True
def open_person_profile(self, *args, **kwargs):
......@@ -357,7 +357,7 @@ class baseBuffer(object):
def pause_audio(self, *args, **kwargs):
""" pauses audio playback."""
def remove_buffer(self, mandatory):
""" Function for removing a buffer. Returns True if removal is successful, False otherwise"""
......@@ -601,7 +601,7 @@ class audioBuffer(feedBuffer):
selected = self.tab.list.get_selected()
if selected == -1:
selected = 0
pub.sendMessage("play-audio", 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:
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):
......@@ -1138,7 +1138,7 @@ class chatBuffer(baseBuffer):
elif attachment["type"] == "audio_message":
link = attachment["audio_message"]["link_mp3"]
player.player.play(url=dict(url=link), set_info=False)
pub.sendMessage("play", object=dict(url=link), set_info=False)
elif attachment["type"] == "link":
output.speak(_("Opening URL..."), True)
......@@ -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"))
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.
......@@ -775,20 +754,10 @@ class Controller(object):
def menu_play_next(self, *args, **kwargs):
return player.player.play_next()
# b = self.get_current_buffer()
# if hasattr(b, "play_next"):
# b.play_next()
# else:
# self.search("me_audio").play_next()
def menu_play_previous(self, *args, **kwargs):
return player.player.play_previous()
# b = self.get_current_buffer()
# if hasattr(b, "play_previous"):
# b.play_previous()
# else:
# self.search("me_audio").play_previous()
def menu_play_all(self, *args, **kwargs):
b = self.get_current_buffer()
......@@ -13,6 +13,7 @@ from sound_lib.stream import URLStream
from sound_lib.main import BassError
from pubsub import pub
from mysc.repeating_timer import RepeatingTimer
from mysc.thread_utils import call_threaded
player = None
log = logging.getLogger("player")
......@@ -46,17 +47,20 @@ 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")
pub.subscribe(self.play_previous, "play_previous")
pub.subscribe(self.play_next, "play-next")
pub.subscribe(self.play_previous, "play-previous")
def play(self, object, set_info=True, fresh=False):
""" Play an URl Stream.
@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"))
if self.stream != None and self.stream.is_playing == True:
......@@ -129,13 +133,15 @@ class audioPlayer(object):
""" Play all passed songs and adds all of those to the queue.
@list_of_songs list: A list of audio objects returned by VK.
@shuffle bool: If True, the files will be played randomly."""
if self.is_working:
self.playing_track = 0
# Skip all country restricted tracks as they are not playable here.
self.queue = [i for i in list_of_songs if i["url"] != ""]
if shuffle:
call_threaded(self.play, self.queue[self.playing_track])
self.worker = RepeatingTimer(5, self.player_function)
......@@ -153,21 +159,25 @@ class audioPlayer(object):
""" Play the next song in the queue. """
if len(self.queue) == 0:
if self.is_working:
if self.playing_track < len(self.queue)-1:
self.playing_track += 1
self.playing_track = 0
call_threaded(self.play, self.queue[self.playing_track])
def play_previous(self):
""" Play the previous song in the queue. """
if len(self.queue) == 0:
if self.is_working:
if self.playing_track <= 0:
self.playing_track = len(self.queue)-1
self.playing_track -= 1
call_threaded(self.play, self.queue[self.playing_track])
def check_is_playing(self):
""" check if the player is already playing a stream. """
......@@ -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 = []
......@@ -17,8 +17,8 @@ from sound_lib import output, input
log = logging.getLogger("sound")
def recode_audio(filename, quality=4.5):
subprocess.call(r'"%s" -q %r "%s"' % (os.path.join(paths.app_path(), 'oggenc2.exe'), quality, filename))
def recode_audio(filename, quality=10):
subprocess.call(r'"%s" --downmix -q %r "%s"' % (os.path.join(paths.app_path(), 'oggenc2.exe'), quality, filename))
def get_recording(filename):
# try: