Modified worker in player module so it will set stopped to True after finishing playback
This commit is contained in:
parent
6bd0c10ef2
commit
605f0da751
@ -19,7 +19,6 @@ from sessionmanager import utils
|
|||||||
player = None
|
player = None
|
||||||
log = logging.getLogger("player")
|
log = logging.getLogger("player")
|
||||||
|
|
||||||
# This function will be deprecated when the player works with pubsub events, as will no longer be needed to instantiate and import the player directly.
|
|
||||||
def setup():
|
def setup():
|
||||||
global player
|
global player
|
||||||
if player == None:
|
if player == None:
|
||||||
@ -41,12 +40,16 @@ class audioPlayer(object):
|
|||||||
self.queue = []
|
self.queue = []
|
||||||
# Index of the currently playing track.
|
# Index of the currently playing track.
|
||||||
self.playing_track = 0
|
self.playing_track = 0
|
||||||
|
self.playing_all = False
|
||||||
|
self.worker = RepeatingTimer(5, self.player_function)
|
||||||
|
self.worker.start()
|
||||||
# Status of the player.
|
# Status of the player.
|
||||||
self.stopped = True
|
self.stopped = True
|
||||||
# Modify some default settings present in Bass so it will increase timeout connection, thus causing less "connection timed out" errors when playing.
|
# Modify some default settings present in Bass so it will increase timeout connection, thus causing less "connection timed out" errors when playing.
|
||||||
bassconfig = BassConfig()
|
bassconfig = BassConfig()
|
||||||
# Set timeout connection to 30 seconds.
|
# Set timeout connection to 30 seconds.
|
||||||
bassconfig["net_timeout"] = 30000
|
bassconfig["net_timeout"] = 30000
|
||||||
|
# subscribe all pubsub events.
|
||||||
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")
|
||||||
@ -82,9 +85,7 @@ class audioPlayer(object):
|
|||||||
log.exception("error when stopping the file")
|
log.exception("error when stopping the file")
|
||||||
self.stream = None
|
self.stream = None
|
||||||
self.stopped = True
|
self.stopped = True
|
||||||
if fresh == True and hasattr(self, "worker") and self.worker != None:
|
if fresh == True:
|
||||||
self.worker.cancel()
|
|
||||||
self.worker = None
|
|
||||||
self.queue = []
|
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:
|
||||||
@ -111,9 +112,6 @@ class audioPlayer(object):
|
|||||||
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
|
self.stopped = True
|
||||||
if hasattr(self, "worker") and self.worker != None:
|
|
||||||
self.worker.cancel()
|
|
||||||
self.worker = None
|
|
||||||
self.queue = []
|
self.queue = []
|
||||||
|
|
||||||
def pause(self):
|
def pause(self):
|
||||||
@ -128,6 +126,8 @@ class audioPlayer(object):
|
|||||||
self.stopped = False
|
self.stopped = False
|
||||||
except BassError:
|
except BassError:
|
||||||
pass
|
pass
|
||||||
|
if self.playing_all == False and len(self.queue) > 0:
|
||||||
|
self.playing_all == True
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def volume(self):
|
def volume(self):
|
||||||
@ -157,16 +157,19 @@ class audioPlayer(object):
|
|||||||
if shuffle:
|
if shuffle:
|
||||||
random.shuffle(self.queue)
|
random.shuffle(self.queue)
|
||||||
call_threaded(self.play, self.queue[self.playing_track])
|
call_threaded(self.play, self.queue[self.playing_track])
|
||||||
self.worker = RepeatingTimer(5, self.player_function)
|
self.playing_all = True
|
||||||
self.worker.start()
|
|
||||||
|
|
||||||
def player_function(self):
|
def player_function(self):
|
||||||
""" Check if the stream has reached the end of the file so it will play the next song. """
|
""" Check if the stream has reached the end of the file so it will play the next song. """
|
||||||
if self.stream != None and self.stream.is_playing == False and self.stopped == False and len(self.stream) == self.stream.position:
|
if self.stream != None and self.stream.is_playing == False and self.stopped == False and len(self.stream) == self.stream.position:
|
||||||
if len(self.queue) == 0 or self.playing_track >= len(self.queue):
|
if self.playing_track >= len(self.queue):
|
||||||
self.worker.cancel()
|
self.stopped = True
|
||||||
|
self.playing_all = False
|
||||||
return
|
return
|
||||||
if self.playing_track < len(self.queue):
|
elif self.playing_all == False:
|
||||||
|
self.stopped = True
|
||||||
|
return
|
||||||
|
elif self.playing_track < len(self.queue):
|
||||||
self.playing_track += 1
|
self.playing_track += 1
|
||||||
self.play(self.queue[self.playing_track])
|
self.play(self.queue[self.playing_track])
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user