本文整理汇总了Python中ui.UI.playinfo方法的典型用法代码示例。如果您正苦于以下问题:Python UI.playinfo方法的具体用法?Python UI.playinfo怎么用?Python UI.playinfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ui.UI
的用法示例。
在下文中一共展示了UI.playinfo方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from ui import UI [as 别名]
# 或者: from ui.UI import playinfo [as 别名]
class Player:
def __init__(self):
self.ui = UI()
self.popen_handler = None
self.play = False
self.pause = False
self.songs = []
self.play_vol = -1
self.play_id = -1
self.view = 'songs'
def popen_recall(self, onExit, popenArgs):
def runInThread(onExit, popenArgs):
self.popen_handler = subprocess.Popen(['mpg123', popenArgs], stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
self.popen_handler.wait()
if self.play:
self.play_id = carousel(0, len(self.songs) - 1, self.play_id + 1)
onExit()
return
thread = threading.Thread(target=runInThread, args=(onExit, popenArgs))
thread.start()
return thread
def recall(self):
self.play = True
song = self.songs[self.play_id]
self.ui.playinfo(song)
self.popen_recall(self.recall, song['source'])
def play_song(self, view, model, idx):
self.view = view
if view == 'songs':
songs = model['songs']
id = model['id']
if idx == self.play_id and songs == self.songs:
if self.pause:
self.resume()
else:
self.pause_song()
else:
self.songs = songs
self.play_id = idx
self.play_vol = id
if self.play:
self.switch()
else:
self.recall()
else:
if self.play:
if self.pause:
self.resume()
else:
self.pause_song()
def pause_song(self):
self.pause = True
os.kill(self.popen_handler.pid, signal.SIGSTOP)
self.ui.playinfo(self.songs[self.play_id], pause=True)
def resume(self):
self.pause = False
os.kill(self.popen_handler.pid, signal.SIGCONT)
self.ui.playinfo(self.songs[self.play_id])
def switch(self):
self.stop()
time.sleep(0.1)
self.recall()
def stop(self):
if self.play and self.popen_handler:
self.popen_handler.kill()
self.play = False
def next_song(self):
self.stop()
time.sleep(0.1)
self.play_id = carousel(0, len(self.songs) - 1, self.play_id + 1)
self.recall()
def prev_song(self):
self.stop()
time.sleep(0.1)
self.play_id = carousel(0, len(self.songs) - 1, self.play_id - 1)
self.recall()