@@ -41,7 +41,7 @@ class Sound:
41
41
please see:
42
42
43
43
* :ref:`sound-loading-modes-streaming`
44
- * The py:class:`pyglet.media.codes .base.StreamingSource` class used
44
+ * The : py:class:`pyglet.media.codecs .base.StreamingSource` class used
45
45
internally
46
46
47
47
To learn about cross-platform loading and file format concerns,
@@ -90,18 +90,12 @@ def play(
90
90
loop : bool = False ,
91
91
speed : float = 1.0 ,
92
92
) -> media .Player :
93
- """Try to play this :py:class:`Sound` and return a :py:class:`~ pyglet.media.player. Player` .
93
+ """Try to play this :py:class:`Sound` and return a | pyglet Player| .
94
94
95
- .. important:: Any :py:class:`Sound` with ``streaming=True`` loses features!
95
+ .. important:: A :py:class:`Sound` with ``streaming=True`` loses features!
96
96
97
- ``loop`` will not work and simultaneous playbacks raise
98
- a :py:class:`RuntimeError`.
99
-
100
- See the following to learn more about the keywords and restrictions:
101
-
102
- * :py:class:`Sound`
103
- * :ref:`sound-advanced-playback-change-aspects-ongoing`
104
- * :ref:`sound-advanced-playback-change-aspects-new`
97
+ Neither ``loop`` nor simultaneous playbacks will work. See
98
+ :py;class:`Sound` and :ref:`sound-loading-modes`.
105
99
106
100
Args:
107
101
volume: Volume (``0.0`` is silent, ``1.0`` is loudest).
@@ -110,6 +104,8 @@ def play(
110
104
loop: ``True`` attempts to restart playback after finishing.
111
105
speed: Change the speed (and pitch) of the sound. Default speed is
112
106
``1.0``.
107
+ Returns:
108
+ A |pyglet Player| for this playback.
113
109
"""
114
110
if isinstance (self .source , media .StreamingSource ) and self .source .is_player_source :
115
111
raise RuntimeError (
@@ -151,14 +147,14 @@ def _on_player_eos():
151
147
return player
152
148
153
149
def stop (self , player : media .Player ) -> None :
154
- """Permanently stop and :py:meth:`~pyglet.media.player.Player.delete` ``player``.
150
+ """Stop and :py:meth:`~pyglet.media.player.Player.delete` ``player``.
155
151
156
- All references in the :py:class:`pyglet.media.Source` player table
157
- will be deleted.
152
+ All references to it in the internal table for
153
+ :py:class:`pyglet.media.Source` will be deleted.
158
154
159
155
Args:
160
- player: A pyglet :py:class:`~pyglet.media.player.Player `
161
- returned from :func:`play_sound` or :py:meth:`Sound.play`.
156
+ player: A pyglet |pyglet Player| from :func:`play_sound `
157
+ or :py:meth:`Sound.play`.
162
158
"""
163
159
player .pause ()
164
160
player .delete ()
@@ -179,9 +175,8 @@ def is_playing(self, player: media.Player) -> bool:
179
175
"""``True`` if ``player`` is currently playing, otherwise ``False``.
180
176
181
177
Args:
182
- player: A pyglet :py:class:`~pyglet.media.player.Player`
183
- returned from :py:meth:`Sound.play <.Sound.play>` or
184
- :func:`play_sound`.
178
+ player: A |pyglet Player| from :func:`play_sound` or
179
+ :py:meth:`Sound.play`.
185
180
186
181
Returns:
187
182
``True`` if the passed pyglet player is playing.
@@ -192,9 +187,8 @@ def get_volume(self, player: media.Player) -> float:
192
187
"""Get the current volume.
193
188
194
189
Args:
195
- player: A pyglet :py:class:`~pyglet.media.player.Player`
196
- returned from :py:meth:`Sound.play <.Sound.play>` or
197
- :func:`play_sound`.
190
+ player: A |pyglet Player| from :func:`play_sound` or
191
+ :py:meth:`Sound.play`.
198
192
Returns:
199
193
A volume between ``0.0`` (silent) and ``1.0`` (full volume).
200
194
"""
@@ -205,8 +199,8 @@ def set_volume(self, volume: float, player: media.Player) -> None:
205
199
206
200
Args:
207
201
volume: Floating point volume. 0 is silent, 1 is full.
208
- player: A pyglet :py:class:`~pyglet.media.player.Player`
209
- returned from :func:`play_sound` or :py:meth:`Sound.play`.
202
+ player: A | pyglet Player| from :func:`play_sound` or
203
+ :py:meth:`Sound.play`.
210
204
"""
211
205
player .volume = volume
212
206
@@ -215,18 +209,19 @@ def get_stream_position(self, player: media.Player) -> float:
215
209
zero when it is done playing.
216
210
217
211
Args:
218
- player: Player returned from :func:`play_sound`.
212
+ player: A |pyglet Player| from :func:`play_sound` or
213
+ :py:meth:`Sound.play`.
219
214
"""
220
215
return player .time
221
216
222
217
223
218
def load_sound (path : str | Path , streaming : bool = False ) -> Sound :
224
219
"""Load a file as a :py:class:`Sound` data object.
225
220
226
- .. important:: Using `` streaming=True`` disables certain features!
221
+ .. important:: A :py:class:`Sound` with `` streaming=True`` loses features!
227
222
228
- These include looping and multiple playbacks. Please
229
- see :py: class:`Sound` to learn more .
223
+ Neither ``loop`` nor simultaneous playbacks will work. See
224
+ :py; class:`Sound` and :ref:`sound-loading-modes` .
230
225
231
226
Args:
232
227
path: a path which may be prefixed with a
@@ -261,18 +256,20 @@ def play_sound(
261
256
loop : bool = False ,
262
257
speed : float = 1.0 ,
263
258
) -> media .Player | None :
264
- """Try to play the ``sound`` and return a :py:class:`~ pyglet.media.player. Player` .
259
+ """Try to play the ``sound`` and return a | pyglet Player| .
265
260
266
- .. note:: The ``sound`` **must** be a :py:class:`Sound` object!
261
+ The ``sound`` must be a loaded :py:class:`Sound` object. If you
262
+ pass a path or :py:class:`str`, the function will raise a
263
+ :py:class:`TypeError.`
267
264
268
- See the following to load audio from file paths:
265
+ .. important:: A :py:class:`Sound` with ``streaming=True`` loses features!
269
266
270
- * :ref:`sound-basics-loading`
271
- * :ref:`sound-loading-modes`
272
- * :py:func:`load_sound`
273
- * :py:class:`Sound`
267
+ Neither ``loop`` nor simultaneous playbacks will work. See
268
+ :py;class:`Sound` and :ref:`sound-loading-modes`.
274
269
275
270
The output and return value depend on whether playback succeeded:
271
+ .. # Note: substitutions don't really work inside tables, so the
272
+ .. # pyglet player below is left as a normal class cross-reference.
276
273
277
274
.. list-table::
278
275
:header-rows: 1
@@ -289,21 +286,11 @@ def play_sound(
289
286
- N/A
290
287
- A pyglet :py:class:`~pyglet.media.player.Player`
291
288
292
- See the following to learn more:
293
-
294
- * :ref:`sound-basics-sound_vs_player`
295
- * :ref:`sound-advanced-playback`
296
-
297
- .. important:: Any :py:class:`Sound` with ``streaming=True`` loses features!
298
-
299
- ``loop`` will not work and simultaneous playbacks raise
300
- a :py:class:`RuntimeError`.
301
-
302
289
To learn more about the ``streaming`` keyword and restrictions, please see:
303
290
304
291
* :py:class:`Sound`
305
- * :ref:`sound-advanced -playback-change-aspects-ongoing`
306
- * :ref:`sound-advanced -playback-change-aspects-new`
292
+ * :ref:`sound-intermediate -playback-change-aspects-ongoing`
293
+ * :ref:`sound-intermediate -playback-change-aspects-new`
307
294
308
295
Args:
309
296
sound: A :py:class:`Sound` instance or ``None``.
@@ -315,9 +302,8 @@ def play_sound(
315
302
values higher than ``1.0`` raise the pitch.
316
303
317
304
Returns:
318
- A :py:class:` pyglet.media. Player` instance for the playback or
305
+ A | pyglet Player| instance for this playback or
319
306
``None`` if playback failed.
320
-
321
307
"""
322
308
if sound is None :
323
309
logger .warning ("Unable to play sound, no data passed in." )
@@ -338,12 +324,11 @@ def play_sound(
338
324
339
325
340
326
def stop_sound (player : media .Player ) -> None :
341
- """Stop a pyglet player for a which is currently playing.
327
+ """Stop and delete a | pyglet Player| which is currently playing.
342
328
343
329
Args:
344
- player: A pyglet :py:class:`~pyglet.media.player.Player`
345
- returned from :py:meth:`Sound.play <.Sound.play>` or
346
- :func:`play_sound`.
330
+ player: A pyglet |pyglet Player| from :py:func:`play_sound`
331
+ or :py:meth:`Sound.play`.
347
332
"""
348
333
349
334
if not isinstance (player , media .Player ):
0 commit comments