Added some modifications to the way the media player works

This commit is contained in:
Manuel Cortez 2019-01-22 17:41:39 -06:00
parent cbcc6f812a
commit 91317b7a41
2 changed files with 44 additions and 22 deletions

View File

@ -218,12 +218,12 @@ class Controller(object):
call_threaded(utils.download_file, url, filename, self.window) call_threaded(utils.download_file, url, filename, self.window)
def play_audio(self, audio_object): def play_audio(self, audio_object):
# Restricted audios does not include an URL paramether. # Restricted audios don't include an URL paramether.
# Restriction can be due to licensed content to unauthorized countries. # Restriction can be due to licensed content to unauthorized countries.
if "url" in audio_object and audio_object["url"] =="": 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")) self.notify(message=_("This file could not be played because it is not allowed in your country"))
return return
call_threaded(player.player.play, audio_object) call_threaded(player.player.play, audio_object, fresh=True)
def play_audios(self, audios): def play_audios(self, audios):
player.player.play_all(audios, shuffle=self.window.player_shuffle.IsChecked()) player.player.play_all(audios, shuffle=self.window.player_shuffle.IsChecked())
@ -601,24 +601,26 @@ class Controller(object):
return player.player.pause() return player.player.pause()
else: else:
b = self.get_current_buffer() b = self.get_current_buffer()
if hasattr(b, "play_audio"): if hasattr(b, "play_all"):
b.play_audio() b.play_all()
else: else:
self.search("me_audio").play_audio() self.search("me_audio").play_all()
def menu_play_next(self, *args, **kwargs): def menu_play_next(self, *args, **kwargs):
b = self.get_current_buffer() return player.player.play_next()
if hasattr(b, "play_next"): # b = self.get_current_buffer()
b.play_next() # if hasattr(b, "play_next"):
else: # b.play_next()
self.search("me_audio").play_next() # else:
# self.search("me_audio").play_next()
def menu_play_previous(self, *args, **kwargs): def menu_play_previous(self, *args, **kwargs):
b = self.get_current_buffer() return player.player.play_previous()
if hasattr(b, "play_previous"): # b = self.get_current_buffer()
b.play_previous() # if hasattr(b, "play_previous"):
else: # b.play_previous()
self.search("me_audio").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()

View File

@ -27,6 +27,7 @@ class audioPlayer(object):
self.vol = 100 self.vol = 100
self.is_working = False self.is_working = False
self.queue = [] self.queue = []
self.playing_track = 0
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()
@ -36,7 +37,7 @@ class audioPlayer(object):
if config.app["app-settings"]["use_proxy"] == True: if config.app["app-settings"]["use_proxy"] == True:
bassconfig["net_proxy"] = b"socializer:socializer@socializer.su:3128" bassconfig["net_proxy"] = b"socializer:socializer@socializer.su:3128"
def play(self, url, set_info=True): def play(self, url, set_info=True, fresh=False):
if self.stream != None and self.stream.is_playing == True: if self.stream != None and self.stream.is_playing == True:
try: try:
self.stream.stop() self.stream.stop()
@ -44,7 +45,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 hasattr(self, "worker") and self.worker != None: if fresh == True and hasattr(self, "worker") and self.worker != None:
self.worker.cancel() self.worker.cancel()
self.worker = None self.worker = None
self.queue = [] self.queue = []
@ -104,23 +105,42 @@ class audioPlayer(object):
self.stream.volume = self.vol/100.0 self.stream.volume = self.vol/100.0
def play_all(self, list_of_urls, shuffle=False): def play_all(self, list_of_urls, shuffle=False):
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_urls if i["url"] != ""] self.queue = [i for i in list_of_urls if i["url"] != ""]
if shuffle: if shuffle:
random.shuffle(self.queue) random.shuffle(self.queue)
self.play(self.queue[0]) self.play(self.queue[self.playing_track])
self.queue.remove(self.queue[0])
self.worker = RepeatingTimer(5, self.player_function) self.worker = RepeatingTimer(5, self.player_function)
self.worker.start() self.worker.start()
def player_function(self): def player_function(self):
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: if len(self.queue) == 0 or self.playing_track >= len(self.queue):
self.worker.cancel() self.worker.cancel()
return return
self.play(self.queue[0]) if self.playing_track < len(self.queue):
self.queue.remove(self.queue[0]) self.playing_track += 1
self.play(self.queue[self.playing_track])
def play_next(self):
if len(self.queue) == 0:
return
if self.playing_track < len(self.queue):
self.playing_track += 1
else:
self.playing_track = 0
self.play(self.queue[self.playing_track])
def play_previous(self):
if len(self.queue) == 0:
return
if self.playing_track <= 0:
self.playing_track = len(self.queue)-1
else:
self.playing_track -= 1
self.play(self.queue[self.playing_track])
def check_is_playing(self): def check_is_playing(self):
if self.stream == None: if self.stream == None: