本文整理汇总了Python中Library.rand方法的典型用法代码示例。如果您正苦于以下问题:Python Library.rand方法的具体用法?Python Library.rand怎么用?Python Library.rand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Library
的用法示例。
在下文中一共展示了Library.rand方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: go
# 需要导入模块: import Library [as 别名]
# 或者: from Library import rand [as 别名]
class Player:
def go(q):
while (True):
item = q.get()
item()
q.task_done()
def __init__(self, ui):
MPlayer.populate()
# Handle actions asynchronously
self.player_q = queue.Queue()
t = threading.Thread(target=Player.go, args=(self.player_q,))
t.daemon = True
t.start()
# rather static..
self.ui = ui
self.lib = Library()
self.notifier = Notifier();
self.alarm = AlarmClock()
# Really stateful variables
self.lastSong = None
self.mp = None
def get_queue(self):
return self.player_q
def play(self, path):
pass
def next(self):
self.reset()
self.mp = MPlayer()
song = self.lib.rand()
self.ui.pplayer('next'+song.path())
self.mp.loadfile(song.path());
self.lastSong = song
try:
length = float(self.mp.get_property("length"))
self.alarm.set(self.next, length)
except:
self.ui.pplayer('No length found'+song.path())
# default to 250s
self.alarm.set(self.next, 250.0)
self.notifier(song.name());
def pause(self):
self.mp.pause()
def reset(self):
self.alarm.cancel()
if self.mp:
self.mp.quit()
def quit(self):
self.reset()
Library.save(self.lib)
def put(self, action):
self.player_q.put(action)
def delete(self):
if self.lastSong:
self.lastSong.delete()
self.next()