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)
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.
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"))
return
call_threaded(player.player.play, audio_object)
call_threaded(player.player.play, audio_object, fresh=True)
def play_audios(self, audios):
player.player.play_all(audios, shuffle=self.window.player_shuffle.IsChecked())
@ -601,24 +601,26 @@ class Controller(object):
return player.player.pause()
else:
b = self.get_current_buffer()
if hasattr(b, "play_audio"):
b.play_audio()
if hasattr(b, "play_all"):
b.play_all()
else:
self.search("me_audio").play_audio()
self.search("me_audio").play_all()
def menu_play_next(self, *args, **kwargs):
b = self.get_current_buffer()
if hasattr(b, "play_next"):
b.play_next()
else:
self.search("me_audio").play_next()
return player.player.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):
b = self.get_current_buffer()
if hasattr(b, "play_previous"):
b.play_previous()
else:
self.search("me_audio").play_previous()
return player.player.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):
b = self.get_current_buffer()

View File

@ -27,6 +27,7 @@ class audioPlayer(object):
self.vol = 100
self.is_working = False
self.queue = []
self.playing_track = 0
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.
bassconfig = BassConfig()
@ -36,7 +37,7 @@ class audioPlayer(object):
if config.app["app-settings"]["use_proxy"] == True:
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:
try:
self.stream.stop()
@ -44,7 +45,7 @@ class audioPlayer(object):
log.exception("error when stopping the file")
self.stream = None
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 = None
self.queue = []
@ -104,23 +105,42 @@ class audioPlayer(object):
self.stream.volume = self.vol/100.0
def play_all(self, list_of_urls, shuffle=False):
self.playing_track = 0
self.stop()
# Skip all country restricted tracks as they are not playable here.
self.queue = [i for i in list_of_urls if i["url"] != ""]
if shuffle:
random.shuffle(self.queue)
self.play(self.queue[0])
self.queue.remove(self.queue[0])
self.play(self.queue[self.playing_track])
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 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()
return
self.play(self.queue[0])
self.queue.remove(self.queue[0])
if self.playing_track < len(self.queue):
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):
if self.stream == None: