Package elisa :: Package core :: Module player_registry
[hide private]
[frames] | no frames]

Source Code for Module elisa.core.player_registry

  1  # -*- coding: utf-8 -*- 
  2  # Elisa - Home multimedia server 
  3  # Copyright (C) 2006-2008 Fluendo Embedded S.L. (www.fluendo.com). 
  4  # All rights reserved. 
  5  # 
  6  # This file is available under one of two license agreements. 
  7  # 
  8  # This file is licensed under the GPL version 3. 
  9  # See "LICENSE.GPL" in the root of this distribution including a special 
 10  # exception to use Elisa with Fluendo's plugins. 
 11  # 
 12  # The GPL part of Elisa is also available under a commercial licensing 
 13  # agreement from Fluendo. 
 14  # See "LICENSE.Elisa" in the root directory of this distribution package 
 15  # for details on that license. 
 16   
 17  """ 
 18  Player instances access and global players control 
 19  """ 
 20   
 21  __maintainer__ = 'Benjamin Kampmann <benjamin@fluendo.com>' 
 22   
 23   
 24  from elisa.core import log, player 
 25  from elisa.core.utils import classinit 
 26   
 27  from elisa.core.player_engine_registry import PlayerEngineRegistry 
 28   
 29   
30 -class PlayerRegistry(log.Loggable):
31 """ 32 The PlayerRegistry has responsability to create and hold 33 L{elisa.core.player.Player} instances. Additionally it can perform 34 global actions on all the players at the same time. 35 36 Player instances are identified by their name, which must be unique, this 37 is the responsability of the developer. 38 39 @ivar _players: currently instantiated players 40 @type _players: list of L{elisa.core.player.Player} 41 42 @type _player_engine_registry: the L{elisa.core.player_engine_registry.PlayerEngineRegistry} 43 """ 44 45 # Allows property fget/fset/fdel/doc overriding 46 __metaclass__ = classinit.ClassInitMeta 47 __classinit__ = classinit.build_properties 48
49 - def __init__(self):
50 log.Loggable.__init__(self) 51 self._players = [] 52 self._simple_player = None 53 self._id_counter = 0 54 self._player_engine_registry = PlayerEngineRegistry()
55
56 - def initialize(self):
57 """ 58 """ 59 self._player_engine_registry.initialize() 60 self._simple_player = self.create_player() 61 self._simple_player.videosink = None 62 self.info("Initializing")
63
64 - def deinitialize(self):
65 """ 66 """ 67 self._player_engine_registry.deinitialize()
68
69 - def create_player(self):
70 """ 71 Returns a new player instance. 72 73 @rtype: L{elisa.core.player.Player} 74 """ 75 76 self.debug("Creating new player") 77 self._id_counter += 1 78 p = player.Player(self._player_engine_registry) 79 p.name = "player_%s" % self._id_counter 80 self._players.append(p) 81 return p
82
83 - def remove_player(self, player_instance):
84 """ 85 Remove player_instance Player 86 87 @param player_instance: Player instance to remove 88 @type player_instance: L{Player} 89 """ 90 for i in self._players: 91 if i == player_instance: 92 self._players.remove(i) 93 break
94
95 - def _global_action(self, method_name, *params):
96 for player_instance in self._players: 97 method = getattr(player_instance, method_name) 98 method(*params)
99
100 - def play_sound(self, uri):
101 """ 102 Play the sound located at L{uri}. If the simple audio player is already 103 playing, the playback is stopped. The playback of the other players is 104 B{not} touched in any way. 105 106 @param uri: the uri of the sound to play 107 @type uri: L{elisa.core.media_uri.MediaUri} 108 """ 109 self._simple_player.uri = uri 110 self._simple_player.play(trigger_message = False)
111
112 - def play_all(self):
113 """ 114 Set all players into playing mode. 115 """ 116 self._global_action("play")
117
118 - def pause_all(self):
119 """ 120 Pause all players. 121 """ 122 self._global_action("pause")
123
124 - def stop_all(self):
125 """ 126 Stop all currently instantiated players. 127 """ 128 self._global_action("stop")
129
130 - def mute_all(self):
131 """ 132 Mute all players. 133 """ 134 self._global_action("muted__set", True)
135
136 - def unmute_all(self):
137 """ 138 Unmute all players. 139 """ 140 self._global_action("muted__set", False)
141