Updated software

This commit is contained in:
Manuel Cortez 2018-01-25 17:18:51 -06:00
parent 9e06e0c29e
commit 86cfb3bf94
4 changed files with 26 additions and 27 deletions

View File

@ -44,10 +44,9 @@ class Controller(object):
widgetUtils.connect_event(self.window.search, widgetUtils.BUTTON_PRESSED, self.on_search)
widgetUtils.connect_event(self.window.list, widgetUtils.LISTBOX_ITEM_ACTIVATED, self.on_activated)
widgetUtils.connect_event(self.window.list, widgetUtils.KEYPRESS, self.on_keypress)
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.on_play_pause, menuitem=self.window.player_play)
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.on_play, menuitem=self.window.player_play)
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.on_next, menuitem=self.window.player_next)
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.on_previous, menuitem=self.window.player_previous)
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.on_play_all, menuitem=self.window.player_play_all)
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.on_stop, menuitem=self.window.player_stop)
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.on_volume_down, menuitem=self.window.player_volume_down)
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.on_volume_up, menuitem=self.window.player_volume_up)
@ -59,23 +58,28 @@ class Controller(object):
utils.call_threaded(self.search)
def on_activated(self, *args, **kwargs):
utils.call_threaded(self.play)
self.on_play()
def on_keypress(self, ev):
if ev.GetKeyCode() == wx.WXK_RETURN:
utils.call_threaded(self.play)
self.on_play()
elif ev.GetKeyCode() == wx.WXK_SPACE:
self.on_play_pause()
ev.Skip()
def on_play_pause(self, *args, **kwargs):
if player.player.check_is_playing() != False:
return player.player.pause()
return utils.call_threaded(self.play)
elif player.player.stream != None:
player.player.stream.play()
else:
self.on_play()
def on_next(self, *args, **kwargs):
if len(self.results) == 0:
return
item = self.window.get_item()
if item <= len(self.results):
if item < len(self.results)-1:
self.window.list.SetSelection(item+1)
else:
self.window.list.SetSelection(0)
@ -91,8 +95,10 @@ class Controller(object):
self.window.list.SetSelection(len(self.results)-1)
return utils.call_threaded(self.play)
def on_play_all(self, *args, **kwargs):
pass
def on_play(self, *args, **kwargs):
items = self.results[self.window.get_item():]
return utils.call_threaded(player.player.play_all, items, shuffle=self.window.player_shuffle.IsChecked(), extractor=self.extractor)
def on_stop(self, *args, **kwargs):
player.player.stop()
@ -122,14 +128,3 @@ class Controller(object):
for i in self.results:
self.window.list.Append(i.format_track())
self.change_status("")
def play(self):
if len(self.results) == 0:
return
self.change_status(_("Loading song..."))
url = self.extractor.get_download_url(self.results[self.window.get_item()].url)
player.player.play(url)
def play_audios(self, audios):
player.player.play_all(audios, shuffle=self.window.player_shuffle.IsChecked())

View File

@ -27,7 +27,7 @@ class audioPlayer(object):
self.queue = []
self.stopped = True
def play(self, url):
def play(self, item):
if self.stream != None and self.stream.is_playing == True:
try:
self.stream.stop()
@ -42,14 +42,17 @@ class audioPlayer(object):
# Make sure there are no other sounds trying to be played.
if self.is_working == False:
self.is_working = True
if item.download_url == "" and hasattr(self, "extractor"):
item.download_url = self.extractor.get_download_url(item.url)
try:
self.stream = URLStream(url=url)
self.stream = URLStream(url=item.download_url)
except BassError:
log.debug("Error when playing the file {0}".format(url,))
log.debug("Error when playing the file {0}".format(item.title,))
pub.sendMessage("change_status", status=_("Error playing last file"))
return
self.stream.volume = self.vol/100.0
self.stream.play()
pub.sendMessage("change_status", status=_("Playing {0}.").format(item.title))
self.stopped = False
self.is_working = False
@ -76,7 +79,7 @@ class audioPlayer(object):
@property
def volume(self):
if self.stream != None:
# if self.stream != None:
return self.vol
@volume.setter
@ -86,9 +89,10 @@ class audioPlayer(object):
if self.stream != None:
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, extractor=None):
self.stop()
self.queue = list_of_urls
self.extractor = extractor
if shuffle:
random.shuffle(self.queue)
self.play(self.queue[0])

View File

@ -11,6 +11,7 @@ class song(object):
self.duration = ""
self.size = 0
self.url = ""
self.download_url = ""
def format_track(self):
return "{0}. {1}. {2}".format(self.title, self.duration, self.size)

View File

@ -10,7 +10,6 @@ class mainWindow(wx.Frame):
mb.Append(app_, _(u"Application"))
player = wx.Menu()
self.player_play = player.Append(wx.NewId(), _(u"Play"))
self.player_play_all = player.Append(wx.NewId(), _(u"Play all"))
self.player_stop = player.Append(wx.NewId(), _(u"Stop"))
self.player_previous = player.Append(wx.NewId(), _(u"Previous"))
self.player_next = player.Append(wx.NewId(), _(u"Next"))