Player Class

Inheritance diagram of Player

class Player

High-level sound and video player.

Constructor:

__init__()

Methods:

dispatch_event(event_type, *args) Dispatch a single event to the attached handlers.
event(*args) Function decorator for an event handler.
get_texture()
next()
next_source()
pause()
play()
pop_handlers() Pop the top level of event handlers off the stack.
push_handlers(*args, **kwargs) Push a level onto the top of the handler stack, then attach zero or more event handlers.
queue(source)
register_event_type(name) Register an event type with the dispatcher.
remove_handler(name, handler) Remove a single event handler.
remove_handlers(*args, **kwargs) Remove event handlers from the event stack.
seek(time)
seek_next_frame() Step forwards one video frame in the current Source.
set_handler(name, handler) Attach a single event handler.
set_handlers(*args, **kwargs) Attach one or more event handlers to the top level of the handler stack.
update_texture([dt, time])

Events:

on_eos()
on_player_eos() The player ran out of sources.
on_source_group_eos() The current source group ran out of data.

Attributes:

EOS_LOOP Type: str
EOS_NEXT Type: str
EOS_PAUSE Type: str
EOS_STOP Type: str
cone_inner_angle
cone_orientation
cone_outer_angle
cone_outer_gain
eos_action Set the behaviour of the player when it reaches the end of the current source.
event_types Type: list
max_distance
min_distance
pitch
playing
position
source
time
volume

Methods

Player.get_texture()
Player.next()

Warning

Deprecated. Use next_source instead.

Player.next_source()
Player.pause()
Player.play()
Player.queue(source)
Player.seek(time)
Player.seek_next_frame()

Step forwards one video frame in the current Source.

Player.update_texture(dt=None, time=None)

Events

Player.on_eos()
Player.on_player_eos()

The player ran out of sources.

Player.on_source_group_eos()

The current source group ran out of data.

The default behaviour is to advance to the next source group if possible.

Attributes

Player.EOS_LOOP = 'loop'

The player will loop the current stream continuosly.

Warning

Deprecated. Use SourceGroup.loop

Player.EOS_NEXT = 'next'

The player will move on to the next queued stream when it reaches the end of the current source. If there is no source queued, the player will pause.

Warning

Deprecated. Use SourceGroup.advance_after_eos

Player.EOS_PAUSE = 'pause'

The player will pause when it reaches the end of the stream.

Warning

Deprecated. Use SourceGroup.advance_after_eos

Player.EOS_STOP = 'stop'

The player will stop entirely; valid only for ManagedSoundPlayer.

Warning

Deprecated. Use SourceGroup.advance_after_eos

Player.cone_inner_angle
Player.cone_orientation
Player.cone_outer_angle
Player.cone_outer_gain
Player.eos_action

Set the behaviour of the player when it reaches the end of the current source.

This must be one of the constants EOS_NEXT, EOS_PAUSE, EOS_STOP or EOS_LOOP.

Warning

Deprecated. Use SourceGroup.loop and SourceGroup.advance_after_eos

Type:str
Player.event_types = ['on_eos', 'on_player_eos', 'on_source_group_eos']
Player.max_distance
Player.min_distance
Player.pitch
Player.playing
Player.position
Player.source
Player.time
Player.volume

Inherited members

Methods

Player.dispatch_event(event_type, *args)

Dispatch a single event to the attached handlers.

The event is propagated to all handlers from from the top of the stack until one returns EVENT_HANDLED. This method should be used only by EventDispatcher implementors; applications should call the dispatch_events method.

Since pyglet 1.2, the method returns EVENT_HANDLED if an event handler returned EVENT_HANDLED or EVENT_UNHANDLED if all events returned EVENT_UNHANDLED. If no matching event handlers are in the stack, False is returned.

Parameters:
  • event_type (str) – Name of the event.
  • args (sequence) – Arguments to pass to the event handler.
Return type:

bool or None

Returns:

(Since pyglet 1.2) EVENT_HANDLED if an event handler returned EVENT_HANDLED; EVENT_UNHANDLED if one or more event handlers were invoked but returned only EVENT_UNHANDLED; otherwise False. In pyglet 1.1 and earler, the return value is always None.

Player.event(*args)

Function decorator for an event handler.

Usage:

win = window.Window()

@win.event
def on_resize(self, width, height):
    # ...

or:

@win.event('on_resize')
def foo(self, width, height):
    # ...
Player.pop_handlers()

Pop the top level of event handlers off the stack.

Player.push_handlers(*args, **kwargs)

Push a level onto the top of the handler stack, then attach zero or more event handlers.

If keyword arguments are given, they name the event type to attach. Otherwise, a callable’s __name__ attribute will be used. Any other object may also be specified, in which case it will be searched for callables with event names.

classmethod Player.register_event_type(name)

Register an event type with the dispatcher.

Registering event types allows the dispatcher to validate event handler names as they are attached, and to search attached objects for suitable handlers.

Parameters:name (str) – Name of the event to register.
Player.remove_handler(name, handler)

Remove a single event handler.

The given event handler is removed from the first handler stack frame it appears in. The handler must be the exact same callable as passed to set_handler, set_handlers or push_handlers; and the name must match the event type it is bound to.

No error is raised if the event handler is not set.

Parameters:
  • name (str) – Name of the event type to remove.
  • handler (callable) – Event handler to remove.
Player.remove_handlers(*args, **kwargs)

Remove event handlers from the event stack.

See push_handlers for the accepted argument types. All handlers are removed from the first stack frame that contains any of the given handlers. No error is raised if any handler does not appear in that frame, or if no stack frame contains any of the given handlers.

If the stack frame is empty after removing the handlers, it is removed from the stack. Note that this interferes with the expected symmetry of push_handlers and pop_handlers.

Player.set_handler(name, handler)

Attach a single event handler.

Parameters:
  • name (str) – Name of the event type to attach to.
  • handler (callable) – Event handler to attach.
Player.set_handlers(*args, **kwargs)

Attach one or more event handlers to the top level of the handler stack.

See push_handlers for the accepted argument types.

Table Of Contents

Previous topic

MediaThread Class

Next topic

PlayerGroup Class