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


Python MPDClient.seek方法代码示例

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


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

示例1: myMPD

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import seek [as 别名]

#.........这里部分代码省略.........
                #                  "password commmand failed: %s" %
                #                  (self._host, e))
                #db.write_log_to_db_a(ac, "MPD-PW-Error: %s" % str(e), "x",
                #                             "write_also_to_console")
                return None

            # Catch all other possible errors
            except (MPDError, IOError) as e:
                #raise RunError("Could not connect to '%s': "
                #                  "error with password command: %s" %
                #                  (self._host, e))
                db.write_log_to_db_a(ac, "MPD-Error-2: %s" % str(e), "x",
                                             "write_also_to_console")
            return None

    def disconnect(self):
        # Try to tell MPD we're closing the connection first
        try:
            self._client.close()

        # If that fails, don't worry, just ignore it and disconnect
        except (MPDError, IOError):
            pass

        try:
            self._client.disconnect()

        # Disconnecting failed, so use a new client object instead
        # This should never happen.  If it does, something is seriously broken,
        # and the client object shouldn't be trusted to be re-used.
        except (MPDError, IOError):
            self._client = MPDClient()

    def exec_command(self, db, ac, command, value):
        """spread out exec commands"""
        result = None
        try:
            if command == "access":
                result = self.mpd_access(db, ac)
            if command == "play":
                result = self._client.play()
            if command == "update":
                result = self._client.update()
            if command == "song":
                result = self._client.currentsong()
            if command == "status":
                result = self._client.status()
            if command == "add":
                result = self._client.add(value)
            if command == "consume":
                result = self._client.consume(value)
            if command == "crossfade":
                result = self._client.crossfade(value)
            if command == "seek":
                result = self._client.seek(value)
            if command == "repeat":
                result = self._client.repeat(value)
            if command == "random":
                result = self._client.random(value)
            if command == "single":
                result = self._client.single(value)
            if command == "replay_gain_mode":
                result = self._client.replay_gain_mode(value)
            if command == "next":
                result = self._client.next()
            if command == "setvol":
                result = self._client.setvol(value)
            # via mpc-client
            if command == "crop":
                result = mpc_client(db, ac, "crop", value)
            if command == "vol":
                result = mpc_client(db, ac, "volume", value)
            # via os
            if command == "reload-1":
                result = run_cmd(db, ac, "killall", value)
            if command == "reload-2":
                result = run_cmd(db, ac, "mpd", value)
            return result

        # Couldn't get the current cmd, so try reconnecting and retrying
        except (MPDError, IOError) as e:
            # No error handling required here
            # Our disconnect function catches all exceptions, and therefore
            # should never raise any.
            error_msg = "MPD-Error-3: %s" % str(e)

            if value is not None:
                error_msg = error_msg + ", cmd: " + value
                #db.write_log_to_db_a(ac, "MPD-E-3 cmd-value: " + value, "x",
                #                             "write_also_to_console")
            if str(e) == "Not connected":
                error_msg = error_msg + ", try recon.:"
                db.write_log_to_db_a(ac, error_msg, "x",
                                                "write_also_to_console")
                self.connect(db, ac)
                self.exec_command(db, ac, command, value)
            else:
                db.write_log_to_db_a(ac, error_msg, "x",
                                                "write_also_to_console")
            return None
开发者ID:srb-fm,项目名称:admin-srb,代码行数:104,代码来源:lib_mpd.py

示例2: library

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import seek [as 别名]
class MPCWebSimple:
	"""Simple MPD Web Client

	GOALS
	CherryPyMPC 0.2 will be able to:
		- display playlist, file tree, and artist/album tree in different tabs
			(without reloading the whole page)
		- update the library (auto refresh when done)
		- seek in a song, graphically
		- be styled much better than 0.1 :-)

	REQS
		- python 2.x
		- python-mpd
		- cherrypy
		
	RUN
		- ./cherrypympc.py"""

# init
	def __init__(self, host, port, passw):
		self.__app__ = "CherryPyMPC 0.2 (static/iframe)"
		self.c = MPDClient()
		self.c.connect(host, port)
		if passw:
			self.c.password(passw)

# actions
	def play(self):
		self.c.play()
		raise cherrypy.HTTPRedirect("/")

	def pause(self):
		self.c.pause()
		raise cherrypy.HTTPRedirect("/")

	def stop(self):
		self.c.stop()
		raise cherrypy.HTTPRedirect("/")

	def prev(self):
		self.c.previous()
		raise cherrypy.HTTPRedirect("/")

	def next(self):
		self.c.next()
		raise cherrypy.HTTPRedirect("/")

	def playno(self, pos):
		if pos:
			self.c.playid(int(pos))
		raise cherrypy.HTTPRedirect("/")

	def addsong(self, song):
		self.c.add(song[1:-1])
		raise cherrypy.HTTPRedirect("/")

	def seek(self, pos, secs):
		self.c.seek(pos, secs)
		cherrypy.response.headers['content-type']='text/plain'
		return "OK"

	def update(self):
		self.c.update()
		cherrypy.response.headers['content-type']='text/plain'
		return "OK"

	def findadd(self, field, query, field2=None, query2=None):
		if field2 and query2:
			self.c.findadd(field, query, field2, query2)
		else:
			self.c.findadd(field, query)
		raise cherrypy.HTTPRedirect("/")

# subframe html
	def playlist(self):
		current_track = self.c.currentsong()['pos']
		plinfo = self.c.playlistinfo()
		pltable = "<table class='playlist'><tr class='header'><th>&nbsp;</th><th>Artist</th><th>Track</th><th>Lengtr</th></tr>"
		for item in plinfo:
			trclass = ""
			if item["pos"] == current_track:
				trclass = " class='currentsong'"
			pltable += "<tr{tr_class} onclick='top.location.href=\"/playno?pos={plpos}\"'><td><img src='/img/musicfile.png' /></td><td>{artist}</td><td>{title}</td><td class='tracklen'>{length}</td></tr>".format( \
					plpos=item["pos"],
					artist=item.get("artist", "&nbsp;"),
					title=item.get("title", item["file"].split("/")[-1]),
					length=SecToTimeString(item["time"]),
					tr_class=trclass)
		pltable += "</table>"
		return self.surround_head_tags_basic(pltable)

	def filetree(self):
		treelist = TreeList(self.c.list('file'))
		def make_ul(tlist, path=[], level=0):
			r = "<ul" + ("" if (level is not 0) else " class='tree'") + ">"
			if len(tlist) > 1:
				flist = sorted(tlist[1:])
				for filename in flist:
					liclass = "" if (filename is not flist[-1] or len(tlist[0].keys()) > 1) else " class='last'"
#.........这里部分代码省略.........
开发者ID:casmarrav,项目名称:cherrypympc,代码行数:103,代码来源:cherrypympc.py

示例3: __init__

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import seek [as 别名]

#.........这里部分代码省略.........
		status = self.c.status()

		# Save current state
		self.last_mode   = self.mode
		self.last_genre  = self.genre
		self.last_album  = temp.get("album","")
		self.last_artist = temp.get("artist","")
		self.last_song   = temp.get("pos","")
		self.last_time 	 = status.get("elapsed","")
	
	
	def undo(self):
		# Reverse the last action (i.e. back to the last time save_state() was called)
		self.c.stop()
		self.c.clear()
		this_song = self.last_song
		this_time = self.last_time

		if self.last_mode=="track":
			if self.genre=="" or self.genre=="All":
				self.c.add("/")			
			else:
				self.c.findadd("genre",self.genre)
			self.c.random(1)
			self.c.play()
		elif self.last_mode=="album":
			self.mode = "album"
			self.c.random(0)
			self.play_album(self.last_album,self.last_artist)
		
		# Attempt to seek to the previous track and album
		try:
			if this_song and this_time:
				self.c.seek(this_song,int(round(float(this_time))))
			elif this_song:
				self.c.play(this_song)
		except:
			print "# Could not seek to song and track"
		
		
	def generate_track_lengths(self):
		# Build list of track lengths (used for display)
		self.track_lengths = []
		self.track_names = []
		for track in self.c.playlistid():
			if track.get("time","")<>"":
				self.track_lengths.append(float(track.get("time","")))
				self.track_names.append(track.get("title",""))


	def generate_album_list(self):
		print "+ Updating MPD database"
		self.c.update() #need to wait for this somehow

		# TODO - check for file
		fid = open(self.music_list,'wt')
		all_genres = list(self.c.list('genre'))
		self.albums=[]
		print "+ Generating database..."
		t_songs = 0
		t_albums = 0		
		
		for g in all_genres:
			if not (g=="" or g=="Video"):
				songs = self.c.find('genre',g)
				self.n[g] = len(songs)
开发者ID:Bisxuit,项目名称:dukebox,代码行数:70,代码来源:dukebox_player.py

示例4: int

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import seek [as 别名]
				newvol = int(stats['volume']) + 5
				if newvol > 100:
					newvol = 100
				client.setvol(newvol)	
			elif action == ACTION_VOLUME_DOWN:
				newvol = int(stats['volume']) - 5
				if newvol < 0:
					newvol = 0
				client.setvol(newvol)
			elif action == ACTION_NEXT:
				client.next()
			elif action == ACTION_PREV:
				client.previous()
			elif action == ACTION_REWIND:
				try:
					client.seek(stats['song'],0)
				except:
					print("Can't seek to beginning!")
			elif action == ACTION_PLAYPAUSE:
				if stats['state'] == "stop":
					client.play()
				if stats['state'] == "play":
					client.pause(1)
				if stats['state'] == "pause":
					client.pause(0)
			else:
				print('Unexpected action queue item: {0}'.format(action))
	
		# If he haven't pinged in a while, do so as a keepalive.
		if time.clock()-last_ping > 5:
			client.ping()
开发者ID:JimTheCactus,项目名称:RaspberryPiMPDJukebox,代码行数:33,代码来源:musicbox.py


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