Implemented play_all, plays all from the selected audio in the buffer

This commit is contained in:
Manuel Cortez 2016-03-23 08:17:45 -06:00
parent 1806db5670
commit 15206fa790
3 changed files with 44 additions and 0 deletions

View File

@ -141,6 +141,7 @@ class audioBuffer(feedBuffer):
def connect_events(self):
widgetUtils.connect_event(self.tab.play, widgetUtils.BUTTON_PRESSED, self.play_audio)
widgetUtils.connect_event(self.tab.play_all, widgetUtils.BUTTON_PRESSED, self.play_all)
super(audioBuffer, self).connect_events()
def play_audio(self, *args, **kwargs):
@ -154,3 +155,7 @@ class audioBuffer(feedBuffer):
a.dialog.get_response()
a.dialog.Destroy()
def play_all(self, *args, **kwargs):
selected = self.tab.list.get_selected()
audios = [i["url"] for i in self.session.db[self.name]["items"][selected:]]
pub.sendMessage("play-audios", audios=audios)

View File

@ -62,6 +62,7 @@ class Controller(object):
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")
widgetUtils.connect_event(self.window, widgetUtils.CLOSE_EVENT, self.exit)
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.update_buffer, menuitem=self.window.update_buffer)
@ -71,6 +72,7 @@ class Controller(object):
pub.unsubscribe(self.in_post, "posted")
pub.unsubscribe(self.download, "download-file")
pub.unsubscribe(self.play_audio, "play-audio")
pub.unsubscribe(self.play_audios, "play-audios")
pub.unsubscribe(self.view_post, "open-post")
def login(self):
@ -101,6 +103,9 @@ class Controller(object):
def play_audio(self, audio_object):
call_threaded(player.player.play, audio_object)
def play_audios(self, audios):
player.player.play_all(audios)
def view_post(self, post_object, controller_):
p = getattr(posts, controller_)(self.session, post_object)
p.dialog.get_response()

View File

@ -2,6 +2,7 @@
import sound_lib
from sound_lib.output import Output
from sound_lib.stream import URLStream
from mysc.repeating_timer import RepeatingTimer
player = None
@ -18,28 +19,43 @@ class audioPlayer(object):
self.stream = None
self.vol = 100
self.is_working = False
self.queue = []
self.stopped = True
def play(self, url):
if self.stream != None and self.stream.is_playing == True:
self.stream.stop()
self.stopped = True
if hasattr(self, "worker") and self.worker != None:
self.worker.cancel()
self.worker = None
self.queue = []
# Make sure that there are no other sounds trying to be played.
if self.is_working == False:
self.is_working = True
self.stream = URLStream(url=url)
self.stream.volume = self.vol/100.0
self.stream.play()
self.stopped = False
self.is_working = False
def stop(self):
if self.stream != None and self.stream.is_playing == True:
self.stream.stop()
self.stopped = True
if hasattr(self, "worker") and self.worker != None:
self.worker.cancel()
self.worker = None
self.queue = []
def pause(self):
if self.stream != None:
if self.stream.is_playing == True:
self.stream.pause()
self.stopped = True
else:
self.stream.play()
self.stopped = False
@property
def volume(self):
@ -53,3 +69,21 @@ class audioPlayer(object):
if self.stream != None:
self.stream.volume = self.vol/100.0
def play_all(self, list_of_urls):
if len(self.queue) == 0:
self.queue = list_of_urls
else:
for i in list_of_urls:
self.queue.append(i)
self.play(self.queue[0])
self.queue.remove(self.queue[0])
self.worker = RepeatingTimer(5, self.player_function)
self.worker.start()
def player_function(self):
if self.stream != None and self.stream.is_playing == False and self.stopped == False:
if len(self.queue) == 0:
self.worker.cancel()
return
self.play(self.queue[0])
self.queue.remove(self.queue[0])