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


Python MPDClient.seekcur方法代码示例

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


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

示例1: Player

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import seekcur [as 别名]
class Player(object):

    def __init__(self,):
        self.setPort('6600')
        self.setHost('localhost')
        self.client = MPDClient()

    def setPort(self, _port):
        self.port = _port

    def setHost(self, _host):
        self.host = _host

    def connectMPD(self):
        try:
            con_id = {'host': self.host, 'port': self.port}
            self.client.connect(**con_id)
        except SocketError:
            print "mpd connection error"
            print traceback.print_exc()
            return False

        print self.client.status()
        return True

    def disconnect(self):
        try:
            self.client.disconnect()
        except SocketError:
            print "mpd connection error"
            print traceback.print_exc()

    def getState(self):
        try:
            return self.client.status()["state"]
        except SocketError:
            print "mpd connection error"
            print traceback.print_exc()

    def getStats(self):
        try:
            return self.client.stats()
        except SocketError:
            print "mpd connection error"
            print traceback.print_exc()

    def playPause(self):
        state = self.client.status()["state"]
        if state == "stop" or state == "pause":
            print "play"
            self.client.play()
        else:
            print "pause"
            self.client.pause()

    def increaseVolume(self, delta):
        volume = int(self.client.status()["volume"])
        volume += delta
        print "settings volume to " + str(volume)
        self.client.setvol(str(volume))

    def decreaseVolume(self, delta):
        volume = int(self.client.status()["volume"])
        volume -= delta
        print "settings volume to " + str(volume)
        self.client.setvol(str(volume))

    def nextSong(self):
        print "next song"
        self.client.next()

    def prevSong(self):
        print "prev song"
        self.client.previous()

    def seekCur(self, time):
        print "seek"
        self.client.seekcur(time)
开发者ID:MrZoidberg,项目名称:RPi-OBABP,代码行数:80,代码来源:player.py

示例2: Controller

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import seekcur [as 别名]
class Controller(object):
    class Mode:
        NONE = 0
        QUEUE = 1
        RANDOM = 2

    def __init__(self, host="/run/mpd/socket"):
        self.cli = MPDClient()
        self.cli.timeout = 10
        self.cli.idletimeout = None
        self.cli.connect(host, 0)
        log.info("Controller connected to MPD server version %s" % self.cli.mpd_version)

        self.mode = Controller.Mode.NONE
        self.switch_mode(Controller.Mode.RANDOM)

    def add_song(self, song):
        self.cli.add(song.as_mpd())

    def add_playlist(self, playlist):
        map(self.cli.add, playlist.as_mpd())

    def switch_mode(self, mode):
        self.mode = Controller.Mode.RANDOM

        if mode == Controller.Mode.RANDOM:
            self.cli.consume(0)
            self.cli.random(1)
            self.cli.repeat(1)
            self.cli.single(0)
            self.cli.clear()

            # Load up a ton of random songs
            playlist = Song.as_mpd_playlist(Song.select())
            map(self.cli.add, playlist)

        if mode == Controller.Mode.QUEUE:
            self.cli.consume(1)
            self.cli.random(0)
            self.cli.repeat(0)
            self.cli.single(0)
            self.cli.clear()

    def status(self):
      current_song = self.cli.currentsong()
      status = self.cli.status().items() + current_song.items()
      if 'title' in current_song:
          try:
              s = Song.get(Song.title == current_song['title'])
              status += s.to_dict().items()
          except Song.DoesNotExist: pass

      status = dict(status)
      status['playlist'] = self.cli.playlistinfo()
      return status

    def play(self):
      self.cli.play()

    def pause(self):
      self.cli.pause()

    def stop(self):
      self.cli.stop()

    def previous(self):
      self.cli.previous()

    def next(self):
      self.cli.next()


    def seek(self, ts):
      self.cli.seekcur(ts);
开发者ID:b1naryth1ef,项目名称:juicebox,代码行数:76,代码来源:controller.py

示例3: __init__

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

#.........这里部分代码省略.........
        print "real time :", real_time,
        print "  = ",abs(read_time-real_time)
        assert abs(read_time-6)<=2.
        assert abs(read_time-real_time)<=2.



    def test_pause(self):
        p1=5
        p2=2
        print "pause"
        self.client.add(self.song1)
        self.client.play()
        time.sleep(p1)
        self.client.pause()
        time.sleep(2)
        self.client.play()
        time.sleep(p2)
        self.client.stop()
        time.sleep(2)#Wait a bit the writing in MPD sticker
        read_time=int(self.client.sticker_get('song',  self.song1, 'last_up'))
        print read_time, "vs", p1+p2
        assert abs(read_time-(p1+p2))<=2.

       
    def test_seek(self):
        seek=30
        delta=5
        print "Seek"
        self.client.add(self.song1)

        self.client.play()
        time.sleep(2)#If not the next command will not be executed
        self.client.seekcur(seek)
        time.sleep(0.2)#If not the next command will not be executed
        self.client.pause()
        time.sleep(2)#Wait a bit the writing in MPD sticker
        print self.client.status()
        read_time=int(self.client.sticker_get('song', self.song1, 'last_up'))
        print read_time, "vs", seek
        print "sticker ", self.client.sticker_get('song', self.song1, 'last_up')
        assert abs(read_time- seek)<=2.

        self.client.play()
        time.sleep(0.2)#If not the next command will not be executed
        self.client.seekcur("+"+str(delta))
        self.client.pause()
        time.sleep(2)#Wait a bit the writing in MPD sticker
        read_time=int(self.client.sticker_get('song', self.song1, 'last_up'))
        print read_time, "vs", seek+delta
        assert abs(read_time- seek-delta)<=2.
        
        self.client.play()
        time.sleep(0.5)#If not the next command will not be executed
        self.client.seekcur("-"+str(2*delta))
        self.client.pause()
        time.sleep(2)#Wait a bit the writing in MPD sticker
        read_time=int(self.client.sticker_get('song', self.song1, 'last_up'))
        print read_time, "vs", seek-delta
        assert abs(read_time- seek+delta)<=2.

        
    
    def test_next(self):
        seek=30
        print "-- Next --"
开发者ID:RaoulChartreuse,项目名称:mpd_bookmark,代码行数:70,代码来源:TestBookmark.py

示例4: MPDBookmark

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import seekcur [as 别名]
class MPDBookmark(object):
    def __init__(self, host="localhost", port=6600, password=None,
                 motif="Podcast", field="album"):
        self.client = MPDClient()
        try:
            self.client.connect(host, port)
            if password:
               self.client.password(password) 
            
        except :
            print "merde"
            print "host = ", host
            print "port = ", port
            print "pass = ", password
            assert False
        self.motif=motif
        self.field=field
        self.boucle()

    def stats(self):
        print "==========================================="
        print "                Version :"
        print self.client.mpd_version
        print "==========================================="
        print "fin du test"
        print self.client.status()


    def wait_action(self):
        self.client.send_idle('player')
        select([self.client], [], [], 60)
        return self.client.fetch_idle()

    
    def verif_motif(self, song):
        return  self.field in song and re.match(self.motif, song[self.field])

    
    def update_song(self, song, ts):
        new_ts=time.time()
        if 'title' in song :
            print "Update song : ", song['title'],
            print "( ",int(new_ts-ts),
            print "/",song['time']," )"
        if self.verif_motif(song):
            last_up=int(new_ts-ts)
            self.client.sticker_set('song', song['file'], 
                                    'last_up', last_up)
    
    def start_song(self, new_song):
        if ('file' in new_song) and 'last_up' in self.client.sticker_list('song', new_song['file']):
            last_up=int(self.client.sticker_get('song', 
                                                new_song['file'], 
                                                'last_up'))
            if abs(int(new_song['time'])-last_up)<=4 :
                last_up=0
            self.client.seekcur(last_up)


    def boucle(self):
        

        state=self.client.status()['state']
        song=self.client.currentsong()
        print "song  :  ", song
        ts=time.time()
        if 'elapsed' in song :
            ts-=float( song['elapsed'])

        while 1 :
            ret=self.wait_action()
            new_state=self.client.status()['state']
            new_song=self.client.currentsong()

            if new_song!=song and new_song!={}:
                self.start_song(new_song)

            if song !={}:
                print "update  ",
                self.update_song(song, ts)

            state= new_state
            song= new_song
            if 'elapsed' in self.client.status():
                ts=time.time()-float( self.client.status()['elapsed'])
开发者ID:RaoulChartreuse,项目名称:mpd_bookmark,代码行数:87,代码来源:mpd_bookmark.py


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