some functions present in the player should not freeze the app while taking place
This commit is contained in:
parent
a0d43ebe0e
commit
04f734bebe
@ -754,20 +754,10 @@ class Controller(object):
|
|||||||
self.search("me_audio").play_all()
|
self.search("me_audio").play_all()
|
||||||
|
|
||||||
def menu_play_next(self, *args, **kwargs):
|
def menu_play_next(self, *args, **kwargs):
|
||||||
return player.player.play_next()
|
pub.sendMessage("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):
|
def menu_play_previous(self, *args, **kwargs):
|
||||||
return player.player.play_previous()
|
pub.sendMessage("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):
|
def menu_play_all(self, *args, **kwargs):
|
||||||
b = self.get_current_buffer()
|
b = self.get_current_buffer()
|
||||||
|
@ -13,6 +13,7 @@ from sound_lib.stream import URLStream
|
|||||||
from sound_lib.main import BassError
|
from sound_lib.main import BassError
|
||||||
from pubsub import pub
|
from pubsub import pub
|
||||||
from mysc.repeating_timer import RepeatingTimer
|
from mysc.repeating_timer import RepeatingTimer
|
||||||
|
from mysc.thread_utils import call_threaded
|
||||||
|
|
||||||
player = None
|
player = None
|
||||||
log = logging.getLogger("player")
|
log = logging.getLogger("player")
|
||||||
@ -49,8 +50,8 @@ class audioPlayer(object):
|
|||||||
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")
|
||||||
pub.subscribe(self.play_previous, "play_previous")
|
pub.subscribe(self.play_previous, "play-previous")
|
||||||
|
|
||||||
def play(self, object, set_info=True, fresh=False):
|
def play(self, object, set_info=True, fresh=False):
|
||||||
""" Play an URl Stream.
|
""" Play an URl Stream.
|
||||||
@ -132,13 +133,15 @@ class audioPlayer(object):
|
|||||||
""" Play all passed songs and adds all of those to the queue.
|
""" Play all passed songs and adds all of those to the queue.
|
||||||
@list_of_songs list: A list of audio objects returned by VK.
|
@list_of_songs list: A list of audio objects returned by VK.
|
||||||
@shuffle bool: If True, the files will be played randomly."""
|
@shuffle bool: If True, the files will be played randomly."""
|
||||||
|
if self.is_working:
|
||||||
|
return
|
||||||
self.playing_track = 0
|
self.playing_track = 0
|
||||||
self.stop()
|
self.stop()
|
||||||
# Skip all country restricted tracks as they are not playable here.
|
# Skip all country restricted tracks as they are not playable here.
|
||||||
self.queue = [i for i in list_of_songs if i["url"] != ""]
|
self.queue = [i for i in list_of_songs if i["url"] != ""]
|
||||||
if shuffle:
|
if shuffle:
|
||||||
random.shuffle(self.queue)
|
random.shuffle(self.queue)
|
||||||
self.play(self.queue[self.playing_track])
|
call_threaded(self.play, self.queue[self.playing_track])
|
||||||
self.worker = RepeatingTimer(5, self.player_function)
|
self.worker = RepeatingTimer(5, self.player_function)
|
||||||
self.worker.start()
|
self.worker.start()
|
||||||
|
|
||||||
@ -156,21 +159,25 @@ class audioPlayer(object):
|
|||||||
""" Play the next song in the queue. """
|
""" Play the next song in the queue. """
|
||||||
if len(self.queue) == 0:
|
if len(self.queue) == 0:
|
||||||
return
|
return
|
||||||
|
if self.is_working:
|
||||||
|
return
|
||||||
if self.playing_track < len(self.queue)-1:
|
if self.playing_track < len(self.queue)-1:
|
||||||
self.playing_track += 1
|
self.playing_track += 1
|
||||||
else:
|
else:
|
||||||
self.playing_track = 0
|
self.playing_track = 0
|
||||||
self.play(self.queue[self.playing_track])
|
call_threaded(self.play, self.queue[self.playing_track])
|
||||||
|
|
||||||
def play_previous(self):
|
def play_previous(self):
|
||||||
""" Play the previous song in the queue. """
|
""" Play the previous song in the queue. """
|
||||||
if len(self.queue) == 0:
|
if len(self.queue) == 0:
|
||||||
return
|
return
|
||||||
|
if self.is_working:
|
||||||
|
return
|
||||||
if self.playing_track <= 0:
|
if self.playing_track <= 0:
|
||||||
self.playing_track = len(self.queue)-1
|
self.playing_track = len(self.queue)-1
|
||||||
else:
|
else:
|
||||||
self.playing_track -= 1
|
self.playing_track -= 1
|
||||||
self.play(self.queue[self.playing_track])
|
call_threaded(self.play, self.queue[self.playing_track])
|
||||||
|
|
||||||
def check_is_playing(self):
|
def check_is_playing(self):
|
||||||
""" check if the player is already playing a stream. """
|
""" check if the player is already playing a stream. """
|
||||||
|
Loading…
Reference in New Issue
Block a user