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


Python UI.playinfo方法代码示例

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


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

示例1: __init__

# 需要导入模块: from ui import UI [as 别名]
# 或者: from ui.UI import playinfo [as 别名]
class Player:
    def __init__(self):
        self.ui = UI()

        self.popen_handler = None
        self.play = False
        self.pause = False
        self.songs = []
        self.play_vol = -1
        self.play_id = -1
        self.view = 'songs'

    def popen_recall(self, onExit, popenArgs):
        def runInThread(onExit, popenArgs):
            self.popen_handler = subprocess.Popen(['mpg123', popenArgs], stdin=subprocess.PIPE, stdout=subprocess.PIPE,
                                                  stderr=subprocess.PIPE)
            self.popen_handler.wait()
            if self.play:
                self.play_id = carousel(0, len(self.songs) - 1, self.play_id + 1)
                onExit()
            return

        thread = threading.Thread(target=runInThread, args=(onExit, popenArgs))
        thread.start()
        return thread

    def recall(self):
        self.play = True
        song = self.songs[self.play_id]
        self.ui.playinfo(song)
        self.popen_recall(self.recall, song['source'])

    def play_song(self, view, model, idx):
        self.view = view

        if view == 'songs':
            songs = model['songs']
            id = model['id']

            if idx == self.play_id and songs == self.songs:
                if self.pause:
                    self.resume()
                else:
                    self.pause_song()
            else:
                self.songs = songs
                self.play_id = idx
                self.play_vol = id

                if self.play:
                    self.switch()
                else:
                    self.recall()

        else:
            if self.play:
                if self.pause:
                    self.resume()
                else:
                    self.pause_song()

    def pause_song(self):
        self.pause = True
        os.kill(self.popen_handler.pid, signal.SIGSTOP)
        self.ui.playinfo(self.songs[self.play_id], pause=True)

    def resume(self):
        self.pause = False
        os.kill(self.popen_handler.pid, signal.SIGCONT)
        self.ui.playinfo(self.songs[self.play_id])

    def switch(self):
        self.stop()
        time.sleep(0.1)
        self.recall()

    def stop(self):
        if self.play and self.popen_handler:
            self.popen_handler.kill()
            self.play = False

    def next_song(self):
        self.stop()
        time.sleep(0.1)
        self.play_id = carousel(0, len(self.songs) - 1, self.play_id + 1)
        self.recall()

    def prev_song(self):
        self.stop()
        time.sleep(0.1)
        self.play_id = carousel(0, len(self.songs) - 1, self.play_id - 1)
        self.recall()
开发者ID:ahonn,项目名称:nada,代码行数:94,代码来源:player.py


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