pyglet.media

Audio and video playback.

pyglet can play WAV files, and if AVbin is installed, many other audio and video formats.

Playback is handled by the Player class, which reads raw data from Source objects and provides methods for pausing, seeking, adjusting the volume, and so on. The Player class implements the best available audio device (currently, only OpenAL is supported):

player = Player()

A Source is used to decode arbitrary audio and video files. It is associated with a single player by “queuing” it:

source = load('background_music.mp3')
player.queue(source)

Use the Player to control playback.

If the source contains video, the Source.video_format attribute will be non-None, and the Player.texture attribute will contain the current video image synchronised to the audio.

Decoding sounds can be processor-intensive and may introduce latency, particularly for short sounds that must be played quickly, such as bullets or explosions. You can force such sounds to be decoded and retained in memory rather than streamed from disk by wrapping the source in a StaticSource:

bullet_sound = StaticSource(load('bullet.wav'))

The other advantage of a StaticSource is that it can be queued on any number of players, and so played many times simultaneously.

pyglet relies on Python’s garbage collector to release resources when a player has finished playing a source. In this way some operations that could affect the application performance can be delayed.

The player provides a Player.delete() method that can be used to release resources immediately. Also an explicit call to `gc.collect()`can be used to collect unused resources.

Modules

drivers
procedural
riff Simple Python-only RIFF reader, supports uncompressed WAV files.

Classes

AVbinSourceLoader
AbstractAudioDriver
AbstractAudioPlayer Base class for driver audio players.
AbstractListener The listener properties for positional audio.
AbstractSourceLoader
AudioData A single packet of audio data.
AudioFormat Audio details.
ManagedSoundPlayer

Warning

Deprecated. Use Player

MediaEvent
MediaThread A thread that cleanly exits on interpreter shutdown, and provides a sleep method that can be interrupted and a termination method.
Player High-level sound and video player.
PlayerGroup Group of players that can be played and paused simultaneously.
RIFFSourceLoader
Source An audio and/or video source.
SourceGroup Read data from a queue of sources, with support for looping.
SourceInfo Source metadata information.
StaticMemorySource Helper class for default implementation of StaticSource. Do not use
StaticSource A source that has been completely decoded in memory.
StreamingSource A source that is decoded as it is being played, and can only be
VideoFormat Video details.
WorkerThread

Functions

get_audio_driver()
get_silent_audio_driver()
get_source_loader()
load(filename[, file, streaming]) Load a source from a file.

Variables

have_avbin = True

bool(x) -> bool

Returns True when the argument x is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.

listener = <pyglet.media._LegacyListener object at 0x905fb6c>

The singleton AbstractListener object.

Warning

Deprecated. Use AbstractAudioDriver.get_listener

Type:AbstractListener

Notes

Defined

  • atexit
  • heapq
  • pyglet
  • sys
  • threading
  • time

Table Of Contents

Previous topic

get_tablets Function

Next topic

pyglet.media.drivers