PYGLET – Current Source Ran-out event of Player Last Updated : 18 Oct, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 Python3 1== # importing pyglet module import pyglet # width of window width = 800 # height of window height = 500 # caption i.e title of the window title = "Geeksforgeeks" # creating a window window = pyglet.window.Window(width, height, title) # creating a media player object player = pyglet.media.Player() # loading a new media media = pyglet.media.load("media.mp4") # video path vidPath ="gfg.mp4" # add this media in the queue player.queue(media) # creating a source object source = pyglet.media.StreamingSource() # load the media from the source MediaLoad = pyglet.media.load(vidPath) # add this media in the queue player.queue(MediaLoad) # play the video player.play() # on draw event @window.event def on_draw(): # clea the window window.clear() # if player source exist # and video format exist if player.source and player.source.video_format: # get the texture of video and # make surface to display on the screen player.get_texture().blit(0, 0) # key press event @window.event def on_key_press(symbol, modifier): # key "p" get press if symbol == pyglet.window.key.P: # pause the video player.pause() # printing message print("Video is paused") # key "r" get press if symbol == pyglet.window.key.R: # resume the video player.play() # printing message print("Video is resumed") # end of source event @window.event def on_eos(): # printing some message print("Current Source ended") # run the pyglet application pyglet.app.run() Output : Comment More infoAdvertise with us Next Article PYGLET â On Insert Text Event Formatted Document R rakshitarora Follow Improve Article Tags : Python Python-gui Python-Pyglet Practice Tags : python Similar Reads PYGLET â Get Current Media Texture in Player In this article, we will see how we can get current media texture 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. Windo 3 min read PYGLET â Release the Resources of Player In this article we will see how we can release the resources 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 3 min read PYGLET â Default Resource Path In this article, we will see how we can access default resource path in 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 2 min read PYGLET â On Insert Text Event Formatted Document In this article, we will see how we can trigger the on insert text event in the 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. Wind 2 min read PYGLET â On Context State Lost Event In this article we will see how we can trigger on context state lost event in 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 2 min read Python VLC MediaPlayer - Getting Current State In this article we will see how we can get current state of the MediaPlayer object in the python vlc module. VLC media player is a free and open-source portable cross-platform media player software and streaming media server developed by the VideoLAN project. MediaPlayer object is the basic object i 2 min read Like