当前位置: 首页>>代码示例>>Python>>正文


Python Playlist.add_dir方法代码示例

本文整理汇总了Python中playlist.Playlist.add_dir方法的典型用法代码示例。如果您正苦于以下问题:Python Playlist.add_dir方法的具体用法?Python Playlist.add_dir怎么用?Python Playlist.add_dir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在playlist.Playlist的用法示例。


在下文中一共展示了Playlist.add_dir方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from playlist import Playlist [as 别名]
# 或者: from playlist.Playlist import add_dir [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:
#.........这里部分代码省略.........
开发者ID:Can-Toi,项目名称:RPi-Player,代码行数:103,代码来源:player.py


注:本文中的playlist.Playlist.add_dir方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。