1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
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
46 __metaclass__ = classinit.ClassInitMeta
47 __classinit__ = classinit.build_properties
48
55
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
65 """
66 """
67 self._player_engine_registry.deinitialize()
68
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
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
96 for player_instance in self._players:
97 method = getattr(player_instance, method_name)
98 method(*params)
99
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
113 """
114 Set all players into playing mode.
115 """
116 self._global_action("play")
117
119 """
120 Pause all players.
121 """
122 self._global_action("pause")
123
125 """
126 Stop all currently instantiated players.
127 """
128 self._global_action("stop")
129
131 """
132 Mute all players.
133 """
134 self._global_action("muted__set", True)
135
137 """
138 Unmute all players.
139 """
140 self._global_action("muted__set", False)
141