PYGLET – Current Source Ran-out event of Player
Last Updated :
18 Oct, 2021
In this article we will see how we can trigger the current source ran-out event of player of PYGLET module in python. Pyglet is easy to use but powerful library for developing visually rich GUI applications like games, multimedia etc. A window is a “heavyweight” object occupying operating system resources. Windows may appear as floating regions or can be set to fill an entire screen (fullscreen). This module allows applications to specify a search path for resources. Pyglet can play WAV files, and if FFmpeg 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. This event get triggered when the current source ran out of data. The default behaviour is to advance to the next source in the playlist if the loop attribute is set to False. If loop attribute is set to True, the current source will start to play again until next_source() is called or loop is set to False.
We can create a window and player object with the help of commands given below
# creating a window
window = pyglet.window.Window(width, height, title)
# creating a player for media
player = pyglet.media.Player()
Below is the syntax of the event
# end of source event
@window.event
def on_eos():
# printing some message
print("Current Source ended")
Below is the implementation
import pyglet
width = 800
height = 500
title = "Geeksforgeeks"
window = pyglet.window.Window(width, height, title)
player = pyglet.media.Player()
media = pyglet.media.load( "media.mp4" )
vidPath = "gfg.mp4"
player.queue(media)
source = pyglet.media.StreamingSource()
MediaLoad = pyglet.media.load(vidPath)
player.queue(MediaLoad)
player.play()
@window .event
def on_draw():
window.clear()
if player.source and player.source.video_format:
player.get_texture().blit( 0 , 0 )
@window .event
def on_key_press(symbol, modifier):
if symbol = = pyglet.window.key.P:
player.pause()
print ( "Video is paused" )
if symbol = = pyglet.window.key.R:
player.play()
print ( "Video is resumed" )
@window .event
def on_eos():
print ( "Current Source ended" )
pyglet.app.run()
|
Output :
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...