Class pyglet.media.AudioPlayer

Abstract low-level interface for playing audio.

AudioPlayer has no knowledge of sources or eos behaviour. Once created, its audio format cannot be modified. The player will attempt to recover automatically from a buffer underrun (but this is not guaranteed).

Applications should not use this class directly, but instead use Player.

Methods

  __init__(self, audio_format)
Create a new audio player for the given audio format.
int get_write_size(self)
Return the maximum number of bytes that can be written.
  write(self, audio_data)
Write audio_data to the stream.
  write_eos(self)
Write an EOS marker to the stream at the current write point.
  write_end(self)
Mark that there will be no more audio data past the current write point.
  play(self)
Begin playback.
  stop(self)
Stop playback.
  clear(self)
Clear all buffered data and prepare for replacement data.
  pump(self)
Called once per loop iteration before checking for eos triggers.
float get_time(self)
Return best guess of current playback time.
bool clear_eos(self)
Check if an EOS marker has been passed, and clear it.
  set_volume(self, volume)
  set_position(self, position)
  set_min_distance(self, min_distance)
  set_max_distance(self, max_distance)
  set_pitch(self, pitch)
  set_cone_orientation(self, cone_orientation)
  set_cone_inner_angle(self, cone_inner_angle)
  set_cone_outer_angle(self, cone_outer_angle)
  set_cone_outer_gain(self, cone_outer_gain)

Instance Variables

AudioFormat audio_format
The player's audio format (read-only).

Constants

  UPDATE_PERIOD = 0.15

Method Details

__init__

(Constructor) __init__(self, audio_format)
Create a new audio player for the given audio format.
Parameters:
audio_format : AudioFormat
Audio format parameters.

get_write_size

get_write_size(self)

Return the maximum number of bytes that can be written.

This is used as a hint for preparing data for write, not as a strict contract.

Returns: int

write

write(self, audio_data)

Write audio_data to the stream.

This method calls AudioData.consume to remove data actually written.

Parameters:
audio_data : AudioData
Data to write.

write_end

write_end(self)

Mark that there will be no more audio data past the current write point.

This does not produce an EOS, but is required to prevent data underrun artifacts.

clear

clear(self)

Clear all buffered data and prepare for replacement data.

The player should be stopped before calling this method.

get_time

get_time(self)
Return best guess of current playback time. The time is relative to the timestamps provided in the data supplied to write. The time is meaningless unless proper care has been taken to clear EOS markers.
Returns:
float: current play cursor time, in seconds.

clear_eos

clear_eos(self)

Check if an EOS marker has been passed, and clear it.

This method should be called repeatedly to clear all pending EOS markers.

Returns:
bool: True if an EOS marker was cleared.