Implemented play_all, plays all from the selected audio in the buffer
This commit is contained in:
parent
1806db5670
commit
15206fa790
@ -141,6 +141,7 @@ class audioBuffer(feedBuffer):
|
|||||||
|
|
||||||
def connect_events(self):
|
def connect_events(self):
|
||||||
widgetUtils.connect_event(self.tab.play, widgetUtils.BUTTON_PRESSED, self.play_audio)
|
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()
|
super(audioBuffer, self).connect_events()
|
||||||
|
|
||||||
def play_audio(self, *args, **kwargs):
|
def play_audio(self, *args, **kwargs):
|
||||||
@ -154,3 +155,7 @@ class audioBuffer(feedBuffer):
|
|||||||
a.dialog.get_response()
|
a.dialog.get_response()
|
||||||
a.dialog.Destroy()
|
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)
|
@ -62,6 +62,7 @@ class Controller(object):
|
|||||||
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_audio, "play-audio")
|
||||||
|
pub.subscribe(self.play_audios, "play-audios")
|
||||||
pub.subscribe(self.view_post, "open-post")
|
pub.subscribe(self.view_post, "open-post")
|
||||||
widgetUtils.connect_event(self.window, widgetUtils.CLOSE_EVENT, self.exit)
|
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)
|
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.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.play_audio, "play-audio")
|
||||||
|
pub.unsubscribe(self.play_audios, "play-audios")
|
||||||
pub.unsubscribe(self.view_post, "open-post")
|
pub.unsubscribe(self.view_post, "open-post")
|
||||||
|
|
||||||
def login(self):
|
def login(self):
|
||||||
@ -101,6 +103,9 @@ class Controller(object):
|
|||||||
def play_audio(self, audio_object):
|
def play_audio(self, audio_object):
|
||||||
call_threaded(player.player.play, 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_):
|
def view_post(self, post_object, controller_):
|
||||||
p = getattr(posts, controller_)(self.session, post_object)
|
p = getattr(posts, controller_)(self.session, post_object)
|
||||||
p.dialog.get_response()
|
p.dialog.get_response()
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
import sound_lib
|
import sound_lib
|
||||||
from sound_lib.output import Output
|
from sound_lib.output import Output
|
||||||
from sound_lib.stream import URLStream
|
from sound_lib.stream import URLStream
|
||||||
|
from mysc.repeating_timer import RepeatingTimer
|
||||||
|
|
||||||
player = None
|
player = None
|
||||||
|
|
||||||
@ -18,28 +19,43 @@ class audioPlayer(object):
|
|||||||
self.stream = None
|
self.stream = None
|
||||||
self.vol = 100
|
self.vol = 100
|
||||||
self.is_working = False
|
self.is_working = False
|
||||||
|
self.queue = []
|
||||||
|
self.stopped = True
|
||||||
|
|
||||||
def play(self, url):
|
def play(self, url):
|
||||||
if self.stream != None and self.stream.is_playing == True:
|
if self.stream != None and self.stream.is_playing == True:
|
||||||
self.stream.stop()
|
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.
|
# Make sure that there are no other sounds trying to be played.
|
||||||
if self.is_working == False:
|
if self.is_working == False:
|
||||||
self.is_working = True
|
self.is_working = True
|
||||||
self.stream = URLStream(url=url)
|
self.stream = URLStream(url=url)
|
||||||
self.stream.volume = self.vol/100.0
|
self.stream.volume = self.vol/100.0
|
||||||
self.stream.play()
|
self.stream.play()
|
||||||
|
self.stopped = False
|
||||||
self.is_working = False
|
self.is_working = False
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
if self.stream != None and self.stream.is_playing == True:
|
if self.stream != None and self.stream.is_playing == True:
|
||||||
self.stream.stop()
|
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):
|
def pause(self):
|
||||||
if self.stream != None:
|
if self.stream != None:
|
||||||
if self.stream.is_playing == True:
|
if self.stream.is_playing == True:
|
||||||
self.stream.pause()
|
self.stream.pause()
|
||||||
|
self.stopped = True
|
||||||
else:
|
else:
|
||||||
self.stream.play()
|
self.stream.play()
|
||||||
|
self.stopped = False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def volume(self):
|
def volume(self):
|
||||||
@ -53,3 +69,21 @@ class audioPlayer(object):
|
|||||||
if self.stream != None:
|
if self.stream != None:
|
||||||
self.stream.volume = self.vol/100.0
|
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])
|
||||||
|
Loading…
Reference in New Issue
Block a user