本文整理汇总了Python中playlist.Playlist.next方法的典型用法代码示例。如果您正苦于以下问题:Python Playlist.next方法的具体用法?Python Playlist.next怎么用?Python Playlist.next使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类playlist.Playlist
的用法示例。
在下文中一共展示了Playlist.next方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from playlist import Playlist [as 别名]
# 或者: from playlist.Playlist import next [as 别名]
class Player:
def __init__(self, name, modules, config, serverHttpRequest, serverMq):
self.name = name
self.serverMq = serverMq;
self.playerModules = dict();
for moduleClass in modules:
print "loading player module " + moduleClass["moduleName"]
self.playerModules[moduleClass["moduleName"]] = moduleClass["class"](config, self.next)
self.playlist = Playlist(config.get("Server", "name"), serverHttpRequest);
self.currentPlayer = None;
self.job = None
def getPlayer(self, name):
LOGGER.info("getting player " + name)
return self.playerModules[name]
def switchPlayer(self, name):
next = self.getPlayer(name)
if self.currentPlayer is None or next != self.currentPlayer:
if self.currentPlayer is not None:
self.currentPlayer.pause()
self.currentPlayer = next
def play(self, track=None):
track = track or self.playlist.get()
if track is not None:
LOGGER.info("playing (name: " + str(track.name) + ", uri: " + str(track.uri) + ") on: " + track.source)
self.switchPlayer(track.source)
if self.currentPlayer.play(track) is False:
self.next();
else:
self.serverMq.emit("player:status", {'status':'PLAYING', "playingId": track._id, "track": track.jsonFull})
#self.setSendProgressJob()
else:
if self.job is not None:
self.job.remove()
self.serverMq.emit("player:status", {'status':"PAUSED"})
LOGGER.info("playlist empty")
def resume(self):
LOGGER.info("curent track = " + str(self.currentPlayer.currentTrack));
if self.currentPlayer.currentTrack is None:
self.play()
else:
self.currentPlayer.resume()
LOGGER.info("emit 'player:status' => 'PLAYING'")
self.serverMq.emit("player:status", {'status':'PLAYING'})
self.setSendProgressJob()
def pause(self):
self.currentPlayer.pause()
if self.job is not None:
self.job.remove()
self.serverMq.emit("player:status", {'status':"PAUSED"})
def next(self):
next = self.playlist.next();
if next is None:
LOGGER.info("Nothing after")
self.pause()
return None
else:
LOGGER.info("playing next")
self.play(next)
return next;
def previous(self):
previous = self.playlist.previous();
if previous is not None:
self.play(previous)
else:
self.pause()
示例2: __init__
# 需要导入模块: from playlist import Playlist [as 别名]
# 或者: from playlist.Playlist import next [as 别名]
class MusicPlayer:
cmd = ['mpg321','-R','RPi']
volume = 0 #Specified in gain dB
def __init__(self):
self.init = True
self.prun = False
self.perror = 0
self.errorlog = []
self.first_out = ("","","","")
self.current_out =("","","","")
self.playing = False
self.playlist = Playlist()
self.adjustVolume(0)
def openPlayer(self):
if not(self.prun):
self.p = Popen(MusicPlayer.cmd,stdin=PIPE,stdout=PIPE,stderr=STDOUT)
self.prun = True
self.pout = Thread(target=self.readoutput)
self.pout.daemon = True
self.pout.start()
return "Opened player"
else:
return "Player already open"
def stopPlayer(self):
if (self.prun):
self.prun = False
self.send("QUIT")
self.p.terminate()
self.p.wait()
return "Stopped player"
else:
return "Player not running"
def adjustVolume(self,adjust):
try:
MusicPlayer.volume = max(-100,min(0,MusicPlayer.volume+int(adjust)))
except TypeError:
return "[Error] Adjustment is not a number"
finally:
call(["amixer","-q","set","PCM","--",str(MusicPlayer.volume)+"dB"])
return "Set volume to %s" % str(MusicPlayer.volume)+"dB"
def send(self,mesg):
self.p.stdin.write(mesg + "\n")
self.p.stdin.flush()
def readoutput(self):
while self.prun:
get_output = self.p.stdout.readline().strip("\n").split(" ")
if get_output[0] == "@S":
new_load = True
elif get_output[0] == "@P":
if get_output[1] == "3":
self.next()
elif get_output[0] == "@E":
self.perror += 1
self.errorlog.append(" ".join(get_output[1:]))
if self.perror > 10:
for item in self.errorlog: print("ERRORLOG: %s" % item)
self.quit()
elif get_output[0] == "@F":
if new_load:
self.first_out = (get_output[1],get_output[2],get_output[3],get_output[4])
new_load = False
else:
self.current_out = (get_output[1],get_output[2],get_output[3],get_output[4])
def quit(self):
self.stopPlayer()
self.init = False
return "Quiting..."
def user_input(self,user_in):
if user_in[0] == "QUIT":
return self.quit()
elif user_in[0] == "PLAYLIST":
try:
if user_in[1] == "LENGTH":
return "Length: %d" % self.playlist.len()
elif user_in[1] == "FILEADD":
if 1 <= len(user_in[2:]) <= 4:
self.playlist.add(PlaylistItem(*user_in[2:]))
return "Adding..." #NEEDS EXIT SPECIFICATION
else:
return "[ADD] Incorrect number of arguments!"
elif user_in[1] == "DIRADD":
if len(user_in[2:]) == 1:
return self.playlist.add_dir(user_in[2])
else:
return "[DIRADD] Incorrect number of arguments!"
elif user_in[1] == "SHOW":
return self.playlist.show()
elif user_in[1] == "CLEAR":
return self.playlist.clear()
elif user_in[1] == "SHUFFLE":
self.playlist.randomize()
if self.playing:
#.........这里部分代码省略.........