In this article we will see how we can update texture of media manually in 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. Manually update the texture from the current source. This happens automatically, so you shouldn’t need to call this method.
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()
In order to do this we use update_texture play method with the player object
Syntax : player.update_texture()
Argument : It takes no argument
Return : It returns None
Below is the implementation
Python3
import pyglet
width = 800
height = 500
title = "Geeksforgeeks"
window = pyglet.window.Window(width, height, title)
vidPath = "gfg.mp4"
player = pyglet.media.Player()
source = pyglet.media.StreamingSource()
MediaLoad = pyglet.media.load(vidPath)
player.queue(MediaLoad)
media = pyglet.media.load( "media.mp4" )
player.queue(media)
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" )
player.update_texture()
pyglet.app.run()
|

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
06 Sep, 2021
Like Article
Save Article