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


Python Playlist.empty方法代码示例

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


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

示例1: Player

# 需要导入模块: from playlist import Playlist [as 别名]
# 或者: from playlist.Playlist import empty [as 别名]
class Player(object):
    #attr_accessor :current_track, :history, :playlist, :current_track, :backend
    attr_accessor(current_track = None)

    def __init__(self):
        from player_backends.gstreamer import Gstreamer
        self.playlist = Playlist()
        self.backend = PlayerBackend(self, Gstreamer)

    def state(self):
        return self.backend.get_state()

    @callback_method
    def schedule_next_track(self):
        self.remove_current_track()

        if self.playlist.empty():
            #print 'nope, no new track'
            self.stop()
            return False

        return self.next_track_as_current()

    @callback_method
    def next_track_as_current(self):
        self.current_track = self.playlist.get()
        #print 'New track: ' + self.current_track.name

    def remove_current_track(self):
        self.current_track = None

    @callback_method
    def play(self):
        #if still playing, return nothing
        if (self.state() == 'playing'): return False
        if (self.state() == 'paused'): return self.resume()
        if (self.playlist.empty() and not self.current_track): return None

        if not self.current_track:
            self.next_track_as_current()

        print 'play'

        result = self.backend.play(self.current_track) #Current track is set
        return result

    def pause(self):
        if self.playing():
            return self.backend.pause()
        elif self.paused():
            return self.resume()

    def resume(self):
        return self.backend.resume()

    @callback_method
    def stop(self):
        self.backend.stop()
        result = self.remove_current_track()
        return result

    def next(self):
        self.schedule_next_track()
        return self.backend.play(self.current_track) #Current track is set

    def playing(self):
        return self.state() == 'playing'

    def paused(self):
        return self.state() == 'paused'

    def stopped(self):
        return self.state() == 'stopped'

    def register_callback(self, name, callback, permanent=False, priority=0):
        return callbacks.RegisterCallback(Player, name, callback, permanent, priority)
开发者ID:LeonB,项目名称:pmpd,代码行数:78,代码来源:player.py


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